Skip to content

Commit

Permalink
Merge branch 'main' into feature/flatten
Browse files Browse the repository at this point in the history
# Conflicts:
#	upickle/test/src/upickle/MacroTests.scala
#	upickleReadme/Readme.scalatex
  • Loading branch information
nox213 committed Oct 15, 2024
2 parents b50cf99 + 004ed7e commit 976c5f9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.github.lolgab.mill.mima._
val scala212 = "2.12.18"
val scala213 = "2.13.11"

val scala3 = "3.4.2"
val scalaNative = "0.5.0"
val scala3 = "3.3.4"
val scalaNative = "0.5.5"
val acyclic = "0.3.12"

val sourcecode = "0.4.2"
Expand Down
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ If you use uPickle and like it, please support it by donating to our Patreon:

- [https://www.patreon.com/lihaoyi](https://www.patreon.com/lihaoyi)

[![Build Status](https://travis-ci.org/lihaoyi/upickle.svg)](https://travis-ci.org/lihaoyi/upickle)


[![Join the chat at https://gitter.im/lihaoyi/upickle](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lihaoyi/upickle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# Developer Docs

* Publishing is automatic on pushing tag to Github
* Updating docs is manual;
* `sbt upickleReadme/run`
* `git checkout gh-pages`
* `cp -R upickleReadme/target/scalatex/* .`
* `git commit -am .`
* `git push origin head`
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ object Macros {
fail(tpe, _),
)


val sealedClassSymbol: Option[Symbol] = sealedParents.find(_ == tpe.typeSymbol)
val segments =
sealedParents
sealedClassSymbol.toList.map(_.fullName.split('.')) ++
sealedParents
.flatMap(_.asClass.knownDirectSubclasses)
.map(_.fullName.split('.'))


// -1 because even if there is only one subclass, and so no name segments
// are needed to differentiate between them, we want to keep at least
// the rightmost name segment
Expand Down
7 changes: 5 additions & 2 deletions upickle/implicits/src-3/upickle/implicits/macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,15 @@ def tagNameImpl0[T](transform: String => String)(using Quotes, Type[T]): Expr[St
inline def shortTagName[T]: String = ${ shortTagNameImpl[T] }
def shortTagNameImpl[T](using Quotes, Type[T]): Expr[String] =
import quotes.reflect._
val sym = TypeTree.of[T].symbol
val sealedClassSymbol = if (TypeRepr.of[T].baseClasses.contains(TypeRepr.of[T].typeSymbol))
Some(TypeRepr.of[T].typeSymbol.fullName.split('.'))
else None
val segments = TypeRepr.of[T].baseClasses
.filter(_.flags.is(Flags.Sealed))
.flatMap(_.children)
.filter(_.flags.is(Flags.Case))
.map(_.fullName.split('.'))
.map(_.fullName.split('.')) ++
sealedClassSymbol.toList

val identicalSegmentCount = Range(0, segments.map(_.length).max - 1)
.takeWhile(i => segments.map(_.lift(i)).distinct.size == 1)
Expand Down
9 changes: 9 additions & 0 deletions upickle/test/src/upickle/MacroTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import upickle.default.{read, write, ReadWriter => RW}

case class Trivial(a: Int = 1)

sealed case class SealedClass(i: Int, s: String)
object SealedClass {
implicit val rw: RW[SealedClass] = upickle.default.macroRW
}

case class KeyedPerson(
@upickle.implicits.key("first_name") firstName: String = "N/A",
@upickle.implicits.key("last_name") lastName: String)
Expand Down Expand Up @@ -894,6 +899,10 @@ object MacroTests extends TestSuite {

}

test("sealedClass"){
assert(write(SealedClass(3, "Hello")) == """{"$type":"SealedClass","i":3,"s":"Hello"}""")
}

test("flatten"){
val a = Users(List(1, 2, 3), Pagination(10, 20, 30))
upickle.default.write[Users](a) ==> """{"Ids":[1,2,3],"limit":10,"offset":20,"total":30}"""
Expand Down
18 changes: 12 additions & 6 deletions upickleReadme/Readme.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
)

@sect("uPickle 4.0.1")
@sect("uPickle 4.0.2")
@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" % "4.0.1" // SBT
ivy"com.lihaoyi::upickle:4.0.1" // Mill
"com.lihaoyi" %% "upickle" % "4.0.2" // SBT
ivy"com.lihaoyi::upickle:4.0.2" // 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" % "4.0.1" // SBT
ivy"com.lihaoyi::upickle::4.0.1" // Mill
"com.lihaoyi" %%% "upickle" % "4.0.2" // SBT
ivy"com.lihaoyi::upickle::4.0.2" // Mill

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

@sect{Version History}
@sect{4.0.2}
@ul
@li
Add support for Scala 3.3.4 and above to re-enable support for the Scala 3.3.x series
@lnk("#635", "https://github.com/com-lihaoyi/upickle/pull/635")
@sect{4.0.1}
@ul
@li
Respect @code{Config#tagName} in @code{Reader.merge} and @code{ReadWriter.merge} @lnk("#619", "https://github.com/com-lihaoyi/upickle/pull/619")
Respect @code{Config#tagName} in @code{Reader.merge} and @code{ReadWriter.merge}
@lnk("#619", "https://github.com/com-lihaoyi/upickle/pull/619")
@sect{4.0.0}
@ul
@li
Expand Down

0 comments on commit 976c5f9

Please sign in to comment.