Skip to content

Commit 0e60cb6

Browse files
committed
4.0.0-RC1
1 parent 1683583 commit 0e60cb6

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

upickle/core/src/upickle/core/Config.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Config {
77
* a `sealed trait`. Defaults to `$type`, but can be configured globally by overriding
88
* [[tagName]], or on a per-`sealed trait` basis via the `@key` annotation
99
*/
10-
def tagName = Annotator.defaultTagKey
10+
def tagName: String = Annotator.defaultTagKey
1111

1212
/**
1313
* Whether to use the fully-qualified name of `case class`es and `case object`s which

upickleReadme/Readme.scalatex

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
)
2727

28-
@sect("uPickle 3.3.1")
28+
@sect("uPickle 4.0.0-RC1")
2929
@div(display.flex, alignItems.center, flexDirection.column)
3030
@div
3131
@a(href := "https://gitter.im/lihaoyi/upickle")(
@@ -74,8 +74,8 @@
7474

7575
@sect{Getting Started}
7676
@hl.scala
77-
"com.lihaoyi" %% "upickle" % "3.3.1" // SBT
78-
ivy"com.lihaoyi::upickle:3.3.1" // Mill
77+
"com.lihaoyi" %% "upickle" % "4.0.0-RC1" // SBT
78+
ivy"com.lihaoyi::upickle:4.0.0-RC1" // Mill
7979

8080
@p
8181
And then you can immediately start writing and reading common Scala
@@ -93,8 +93,8 @@
9393
@p
9494
For ScalaJS applications, use this dependencies instead:
9595
@hl.scala
96-
"com.lihaoyi" %%% "upickle" % "3.3.1" // SBT
97-
ivy"com.lihaoyi::upickle::3.3.1" // Mill
96+
"com.lihaoyi" %%% "upickle" % "4.0.0-RC1" // SBT
97+
ivy"com.lihaoyi::upickle::4.0.0-RC1" // Mill
9898

9999
@sect{Scala Versions}
100100
@p
@@ -148,7 +148,7 @@
148148
@hl.ref(exampleTests, Seq("\"more\"", "\"seqs\"", ""))
149149

150150
@p
151-
@code{Option}s are serialized as JSON lists with 0 or 1 element
151+
@code{Option}s are serialized as nullable values
152152

153153
@hl.ref(exampleTests, Seq("\"more\"", "\"options\"", ""))
154154

@@ -185,7 +185,7 @@
185185
After that, you can begin serializing that case class.
186186

187187
@hl.ref(exampleTests, Seq("object Simple", ""))
188-
@hl.ref(exampleTests, Seq("\"more\"", "\"caseClass\"", ""), " }")
188+
@hl.ref(exampleTests, Seq("\"more\"", "\"caseClass\"", ""))
189189

190190
@p
191191
Sealed hierarchies are serialized as tagged values, the serialized
@@ -253,7 +253,7 @@
253253

254254
Nulls serialize into JSON nulls, as you would expect
255255

256-
@hl.ref(exampleTests, Seq("\"more\"", "\"null\"", ""), " }")
256+
@hl.ref(exampleTests, Seq("test(\"null\")", ""))
257257

258258
@p
259259
uPickle only throws exceptions on unpickling; if a pickler is
@@ -291,6 +291,12 @@
291291
make the default @hl.scala{None}) and uPickle will happily read the
292292
old data, filling in the missing field using the default value.
293293

294+
@p
295+
You can enable serialization of default values a per-field or per-case-class basis
296+
using the @hl.scala{@@upickle.implicits.serializeDefaults(true)}
297+
annotation on that field or @hl.scala{case class}, or globally on a
298+
@sect.ref{Custom Configuration} via @hl.scala{override def serializeDefaults = true}
299+
294300
@sect{Supported Types}
295301
@p
296302
Out of the box, uPickle supports writing and reading the following types:
@@ -328,13 +334,12 @@
328334
serializable up to 64 fields.
329335

330336
@p
331-
Case classes are serialized using the @hl.scala{apply} and
332-
@hl.scala{unapply} methods on their companion objects. This means that
333-
you can make your own classes serializable by giving them companions
334-
@hl.scala{apply} and @hl.scala{unapply}. @hl.scala{sealed} hierarchies
335-
are serialized as tagged unions: whatever the serialization of the
336-
actual object, together with the fully-qualified name of its class, so
337-
the correct class in the sealed hierarchy can be reconstituted later.
337+
Case classes are de-serialized using the @hl.scala{apply} method on their
338+
companion objects. @hl.scala{sealed} hierarchies
339+
are serialized as tagged unions: whatever the serialization of the
340+
actual object, together with the partially-qualified name of its class
341+
in a @hl.scala{"$type": "..."} field, so
342+
the correct class in the sealed hierarchy can be reconstituted later.
338343

339344
@p
340345
That concludes the list of supported types. Anything else is not supported
@@ -378,11 +383,9 @@
378383

379384
@sect{Custom Keys}
380385
@p
381-
382386
uPickle allows you to specify the key that a field is serialized with
383387
via a @hl.scala{@@key} annotation
384388

385-
386389
@hl.ref(exampleTests, Seq("object Keyed", ""))
387390
@hl.ref(exampleTests, Seq("\"keyed\"", "\"attrs\"", ""))
388391

@@ -428,6 +431,8 @@
428431
This is useful in cases where you need to override uPickle's default
429432
behavior, for example to preserve compatibility with another JSON library.
430433

434+
435+
431436
@sect{JSON Dictionary Formats}
432437
@p
433438
By default, serializing a @hl.scala{Map[K, V]} generates a nested
@@ -464,6 +469,12 @@
464469
the restriction that dictionary keys can only be strings:
465470

466471
@hl.ref(exampleTests, Seq("msgPackMapKeys", ""))
472+
@sect{Other Per-Case-Class Annotations}
473+
@p
474+
The full list of annotations that can be applied to @hl.scala{case class}es
475+
and @hl.scala{sealed trait}s is below:
476+
477+
@hl.ref(wd / "upickle" / "implicits" / "src" / "upickle" / "implicits" / "key.scala", Nil)
467478

468479
@sect{Custom Configuration}
469480
@p
@@ -586,7 +597,7 @@
586597
@p
587598
uJson comes with some convenient utilities on the `ujson` package:
588599

589-
@hl.ref(wd/'ujson/'src/'ujson/"package.scala", Seq("package object ujson", ""), "// End ujson")
600+
@hl.ref(wd/'ujson/'src/'ujson/"package.scala", Seq("package object ujson"))
590601

591602
@sect{Transformations}
592603
@p
@@ -904,6 +915,50 @@
904915
JSON library, and inherits a lot of it's performance from Erik's work.
905916

906917
@sect{Version History}
918+
@sect{4.0.0-RC1}
919+
@ul
920+
@li
921+
@b{4.0.0 is a major breaking change in uPickle, including in the serialization
922+
format for many common data types (@hl.scala{Option}s, @hl.scala{sealed trait}s,
923+
etc.), as well as breaking binary compatibility. Please be
924+
careful upgrading and follow the instructions below.}
925+
@li
926+
uPickle 4.0.0-RC1 is a release candidate. It breaks backwards compatibility with
927+
uPickle 3.x (binary and serialization), but makes no promises for compatibility
928+
with uPickle 4.0.0 final. Hopefully nothing will need to change between 4.0.0-RC1
929+
and 4.0.0 final, but it cannot be guaranteed.
930+
@li
931+
Shorten @code{$type} tag used for discriminating @hl.scala{sealed trait} cases
932+
@lnk("#594", "https://github.com/com-lihaoyi/upickle/pull/596")
933+
@li
934+
Unbox first level of @code{Options} when serializing JSON
935+
@lnk("#598", "https://github.com/com-lihaoyi/upickle/pull/598")
936+
@li
937+
Make uPickle derivation in Scala 3 call @code{apply} method instead of @code{new}
938+
@lnk("#607", "https://github.com/com-lihaoyi/upickle/pull/607")
939+
@li
940+
Allow field-level and class-level application of @code{serializeDefaults} as an annotation
941+
@lnk("#608", "https://github.com/com-lihaoyi/upickle/pull/608").
942+
@li
943+
To upgrade to uPickle 4.0.0 from uPickle 3.x while preserving the existing serialization
944+
format, please add @hl.scala{override def objectTypeKeyWriteFullyQualified = true} and
945+
@hl.scala{override def optionsAsNulls = false} to your upickle
946+
@sect.ref{Custom Configuration}. If you are currently using @code{upickle.default}, please define
947+
a @sect.ref{Custom Configuration} and replace all usage of @code{upickle.default}
948+
with it. This will preserve the prior serialization format, allowing a smooth upgrade
949+
@li
950+
@hl.scala{override def objectTypeKeyWriteFullyQualified = true} is both forwards and
951+
backwards compatible. Once your entire system is on uPickle 4.0.0, you can incrementally
952+
disable @code{objectTypeKeyWriteFullyQualified}, and uPickle 4.0.0 will be able to read
953+
the generate JSON whether @code{objectTypeKeyWriteFullyQualified} is @hl.scala{true}
954+
or @hl.scala{false}.
955+
@li
956+
@hl.scala{override def optionsAsNulls = false} is @b{not} forwards or backwards
957+
compatible, and cannot be due to the nature of the change in the serialization
958+
format. If you are unable to do a "big bang" upgrade of your entire system (both
959+
code and serialized data) to uPickle 4.0.0, it may be best to continue using
960+
@hl.scala{override def optionsAsNulls = false} for the foreseeable future.
961+
907962
@sect{3.3.1}
908963
@ul
909964
@li

0 commit comments

Comments
 (0)