Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable sum encoding #55

Closed
tindzk opened this issue Jan 15, 2015 · 4 comments
Closed

Configurable sum encoding #55

tindzk opened this issue Jan 15, 2015 · 4 comments

Comments

@tindzk
Copy link
Contributor

tindzk commented Jan 15, 2015

I need to parse the Pandoc format which is produced via aeson. aeson supports configuring the sum encoding which is done as follows in Pandoc:

Aeson.sumEncoding = Aeson.TaggedObject "t" "c"

Obviously, this consumes more space than the current approach chosen by uPickle:

  def annotate[V: ClassTag](rw: R[V], n: String) = R[V]{
    case Js.Arr(Js.Str(`n`), x) => rw.read(x)
  }

Would it be possible to not import annotate by default, so that I could define it manually?

This feature would significantly increase interoperability with other picklers as there doesn't seem to be a common standard on how to serialise classes.

@lihaoyi
Copy link
Member

lihaoyi commented Jan 17, 2015

Possible. Would require some thought as to how to make it work well. Not sure whether typeclasses or virtual-classes would be the way to go for this

tindzk added a commit to tindzk/upickle that referenced this issue Jan 19, 2015
@tindzk
Copy link
Contributor Author

tindzk commented Jan 19, 2015

Here's my first attempt: https://github.com/tindzk/upickle/tree/change-sumencoding

It doesn't work as expected since the implicit is not resolved properly. Do you have any idea how to fix it?

Edit: The fix was simple: The case object needed to be flagged with implicit.

@lihaoyi
Copy link
Member

lihaoyi commented Jul 9, 2015

This is fixed in master https://github.com/lihaoyi/upickle-pprint/blob/master/upickle/shared/src/main/scala/upickle/Api.scala#L7-L40

Now you can define your own upickle bundle and override the CaseR/CaseW sum encoding, swap between the old array-wrapped typetags and type-attribute typetags, and other things. By default I provide import upickle.legacy._ for the old encoding and upickle.default for a seemingly much-more-useful default encoding

@lihaoyi lihaoyi closed this as completed Jul 9, 2015
@tindzk
Copy link
Contributor Author

tindzk commented Jul 9, 2015

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants