Skip to content

Commit

Permalink
Merge branch 'main' into update/argonaut-6.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
scala-steward committed Apr 7, 2023
2 parents 01aabd3 + ecbaccb commit e515299
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.11
0.10.12
38 changes: 35 additions & 3 deletions implicits/src/upickle/implicits/Readers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,56 @@ trait Readers extends upickle.core.Types
}
}

implicit def MapReader1[K, V](implicit k: Reader[K], v: Reader[V]): Reader[collection.Map[K, V]] = {
implicit def MapReader1[K: Reader, V: Reader]: Reader[collection.Map[K, V]] = {
MapReader0[collection.Map, K, V](_.toMap)
}
implicit def MapReader2[K, V](implicit k: Reader[K], v: Reader[V]): Reader[collection.immutable.Map[K, V]] = {
implicit def MapReader2[K: Reader, V: Reader]: Reader[collection.immutable.Map[K, V]] = {
MapReader0[collection.immutable.Map, K, V]{seq =>
val b = collection.immutable.Map.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}
implicit def MapReader3[K, V](implicit k: Reader[K], v: Reader[V]): Reader[collection.mutable.Map[K, V]] = {
implicit def MapReader3[K: Reader, V: Reader]: Reader[collection.mutable.Map[K, V]] = {
MapReader0[collection.mutable.Map, K, V]{seq =>
val b = collection.mutable.Map.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}

implicit def MapReader4[K: Reader, V: Reader]: Reader[collection.mutable.LinkedHashMap[K, V]] = {
MapReader0[collection.mutable.LinkedHashMap, K, V]{seq =>
val b = collection.mutable.LinkedHashMap.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}

implicit def SortedMapReader[K: Reader: Ordering, V: Reader]: Reader[collection.mutable.SortedMap[K, V]] = {
MapReader0[collection.mutable.SortedMap, K, V]{seq =>
val b = collection.mutable.SortedMap.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}

implicit def MapReader6[K: Reader: Ordering, V: Reader]: Reader[collection.immutable.SortedMap[K, V]] = {
MapReader0[collection.immutable.SortedMap, K, V]{seq =>
val b = collection.immutable.SortedMap.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}

implicit def MapReader7[K: Reader: Ordering, V: Reader]: Reader[collection.SortedMap[K, V]] = {
MapReader0[collection.SortedMap, K, V]{seq =>
val b = collection.SortedMap.newBuilder[K, V]
seq.foreach(b += _)
b.result()
}
}

implicit def OptionReader[T: Reader]: Reader[Option[T]] = new SimpleReader[Option[T]] {
override def expectedMsg = "expected sequence"
override def visitArray(length: Int, index: Int) = new ArrVisitor[Any, Option[T]] {
Expand Down
23 changes: 20 additions & 3 deletions implicits/src/upickle/implicits/Writers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,35 @@ trait Writers extends upickle.core.Types
}
}

implicit def MapWriter1[K, V](implicit kw: Writer[K], vw: Writer[V]): Writer[collection.Map[K, V]] = {
implicit def MapWriter1[K: Writer, V: Writer]: Writer[collection.Map[K, V]] = {
MapWriter0[collection.Map, K, V]
}

implicit def MapWriter2[K, V](implicit kw: Writer[K], vw: Writer[V]): Writer[collection.immutable.Map[K, V]] = {
implicit def MapWriter2[K: Writer, V: Writer]: Writer[collection.immutable.Map[K, V]] = {
MapWriter0[collection.immutable.Map, K, V]
}

implicit def MapWriter3[K, V](implicit kw: Writer[K], vw: Writer[V]): Writer[collection.mutable.Map[K, V]] = {
implicit def MapWriter3[K: Writer, V: Writer]: Writer[collection.mutable.Map[K, V]] = {
MapWriter0[collection.mutable.Map, K, V]
}

implicit def MapWriter4[K: Writer, V: Writer]: Writer[collection.mutable.LinkedHashMap[K, V]] = {
MapWriter0[collection.mutable.LinkedHashMap, K, V]
}

implicit def MapWriter5[K: Writer, V: Writer]: Writer[collection.mutable.SortedMap[K, V]] = {
MapWriter0[collection.mutable.SortedMap, K, V]
}

implicit def MapWriter6[K: Writer, V: Writer]: Writer[collection.immutable.SortedMap[K, V]] = {
MapWriter0[collection.immutable.SortedMap, K, V]
}


implicit def MapWriter7[K: Writer, V: Writer]: Writer[collection.SortedMap[K, V]] = {
MapWriter0[collection.SortedMap, K, V]
}

implicit val DurationWriter: Writer[Duration] = new SimpleMapKeyWriter[Duration]{
override def writeString(v: Duration) = v match{
case Duration.Inf => "inf"
Expand Down
57 changes: 57 additions & 0 deletions upickle/test/src/upickle/StructTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,63 @@ object StructTests extends TestSuite {
upack.Arr(upack.Arr(upack.Str("abc"), upack.Str("def")))
)
}

test("variants"){
test("LinkedHashMap") - rw(
scala.collection.mutable.LinkedHashMap("Hello" -> List(1), "World" -> List(1, 2, 3)),
"""{"Hello":[1],"World":[1,2,3]}""",
"""[["Hello",[1]],["World",[1,2,3]]]""",
upack.Obj(
upack.Str("Hello") -> upack.Arr(upack.Int32(1)),
upack.Str("World") -> upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3))
),
upack.Arr(
upack.Arr(upack.Str("Hello"), upack.Arr(upack.Int32(1))),
upack.Arr(upack.Str("World"), upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3)))
)
)
test("SortedMap"){
test("immutable") - rw(
scala.collection.immutable.SortedMap("Hello" -> List(1), "World" -> List(1, 2, 3)),
"""{"Hello":[1],"World":[1,2,3]}""",
"""[["Hello",[1]],["World",[1,2,3]]]""",
upack.Obj(
upack.Str("Hello") -> upack.Arr(upack.Int32(1)),
upack.Str("World") -> upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3))
),
upack.Arr(
upack.Arr(upack.Str("Hello"), upack.Arr(upack.Int32(1))),
upack.Arr(upack.Str("World"), upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3)))
)
)
test("mutable") - rw(
scala.collection.mutable.SortedMap("Hello" -> List(1), "World" -> List(1, 2, 3)),
"""{"Hello":[1],"World":[1,2,3]}""",
"""[["Hello",[1]],["World",[1,2,3]]]""",
upack.Obj(
upack.Str("Hello") -> upack.Arr(upack.Int32(1)),
upack.Str("World") -> upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3))
),
upack.Arr(
upack.Arr(upack.Str("Hello"), upack.Arr(upack.Int32(1))),
upack.Arr(upack.Str("World"), upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3)))
)
)
test("collection") - rw(
scala.collection.SortedMap("Hello" -> List(1), "World" -> List(1, 2, 3)),
"""{"Hello":[1],"World":[1,2,3]}""",
"""[["Hello",[1]],["World",[1,2,3]]]""",
upack.Obj(
upack.Str("Hello") -> upack.Arr(upack.Int32(1)),
upack.Str("World") -> upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3))
),
upack.Arr(
upack.Arr(upack.Str("Hello"), upack.Arr(upack.Int32(1))),
upack.Arr(upack.Str("World"), upack.Arr(upack.Int32(1), upack.Int32(2), upack.Int32(3)))
)
)
}
}
}

test("option"){
Expand Down
27 changes: 22 additions & 5 deletions upickleReadme/Readme.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
)

@sect("uPickle 3.0.0")
@sect("uPickle 3.1.0")
@div(display.flex, alignItems.center, flexDirection.column)
@div
@a(href := "https://gitter.im/lihaoyi/upickle")(
Expand Down Expand Up @@ -74,8 +74,8 @@

@sect{Getting Started}
@hl.scala
"com.lihaoyi" %% "upickle" % "3.0.0" // SBT
ivy"com.lihaoyi::upickle:3.0.0" // Mill
"com.lihaoyi" %% "upickle" % "3.1.0" // SBT
ivy"com.lihaoyi::upickle:3.1.0" // Mill

@p
And then you can immediately start writing and reading common Scala
Expand All @@ -93,8 +93,8 @@
@p
For ScalaJS applications, use this dependencies instead:
@hl.scala
"com.lihaoyi" %%% "upickle" % "3.0.0" // SBT
ivy"com.lihaoyi::upickle::3.0.0" // Mill
"com.lihaoyi" %%% "upickle" % "3.1.0" // SBT
ivy"com.lihaoyi::upickle::3.1.0" // Mill

@sect{Scala Versions}
@p
Expand Down Expand Up @@ -886,6 +886,23 @@
JSON library, and inherits a lot of it's performance from Erik's work.

@sect{Version History}
@sect{3.1.0}
@ul
@li
Across-the-board performance optimizations @lnk("#467", "https://github.com/com-lihaoyi/upickle/pull/467")
@li
Make @hl.scala{derives} properly handle @hl.scala{abstract class}es in Scala 3
@lnk("#470", "https://github.com/com-lihaoyi/upickle/pull/470")
@li
Use a NotGiven implicit to avoid infinite loops caused by
@code{superTypeWriter}/@code{superTypeReader}
@lnk("#471", "https://github.com/com-lihaoyi/upickle/pull/471")
@li
Fix ClassCastException on @hl.scala{import given}
@lnk("#472", "https://github.com/com-lihaoyi/upickle/pull/472")
@li
Added readwriters for @code{SortedMap} and @code{LinkedHashMap}
@lnk("#479", "https://github.com/com-lihaoyi/upickle/pull/479")
@sect{3.0.0}
@ul
@li
Expand Down

0 comments on commit e515299

Please sign in to comment.