amnaredo / test

0 stars 0 forks source link

Allow custom handling of nulls #108

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

Currently the way Reader/Writer handle nulls is hardcoded: null is always converted to and from Js.Null, and corresponding methods are final so they can't be overridden. However, sometimes it makes sense to handle nulls differently, for example, when overriding [de]serialization of options.

Is it possible to allow custom handling of nulls?

ID: 63 Original Author: netvl

amnaredo commented 3 years ago

Yeah it would be nice to do this. Maybe you could move the null handling into the individual Readers/Writers to make them do the right thing? Worth a discussion/prototype

Original Author: lihaoyi

amnaredo commented 3 years ago

@netvl You may find https://github.com/lihaoyi/upickle/pull/43 relevant in case you embark on dealing with this.

Original Author: ramnivas

amnaredo commented 3 years ago

+1, I need this as well.

Would it be feasible to switch order of read0 and read, so that Js.Null is converted to null only if read0.isDefinedAt(Js.Null) is false?

Original Author: megri

amnaredo commented 3 years ago

Duplicate https://github.com/lihaoyi/upickle/issues/40

Original Author: lihaoyi

amnaredo commented 3 years ago

Can we re-open this? #40 was recently closed but I don't believe it addresses this issue -- that null is picked off incredibly early in the deserialization process in a way that can't be overridden.

I'd like to use uPickle on the browser but need to interoperate with other json generators that represent None[String] as null and the Option[String] as the string itself.

40 allows one to represent Option[T] differently from the default -- but not as null and the string itself.

Original Author: bwbecker

amnaredo commented 3 years ago

I just forked upickle, cloned and tried to run the tests. Many of the tests completed successfully, but in the end I received the following errors:

[error] (pprintJS/*:update) sbt.ResolveException: unresolved dependency: com.lihaoyi#derive_sjs0.6_2.11;0.3.7: configuration not public in com.lihaoyi#derive_sjs0.6_2.11;0.3.7: 'test'. It was required from com.lihaoyi#pprint_sjs0.6_2.11;0.3.7 test
[error] (upickleJS/*:update) sbt.ResolveException: unresolved dependency: com.lihaoyi#derive_sjs0.6_2.11;0.3.7: configuration not public in com.lihaoyi#derive_sjs0.6_2.11;0.3.7: 'test'. It was required from com.lihaoyi#upickle_sjs0.6_2.11;0.3.7 test

I don't see a "derive" project in lihaoyi's github. I do note there is a derive package in upickle-pprint.

Suggestions on how to proceed would be welcome.

Original Author: bwbecker

amnaredo commented 3 years ago

You might need to bump the version up to 0.3.8-SNAPSHOT; SBT sometimes gets confused if the project has the same version as a cached artifact

Original Author: lihaoyi