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

Make missing collections deserialize to empty. #257

Closed
wants to merge 1 commit into from

Conversation

SiliconMeeple
Copy link
Contributor

This is certainly more useful for us - we strongly suspect that most other users would expect this too - we do after all have Option[Vector[T]] if we explicitly want to know whether or not the field was there.

(with able assistance by @elulamp)

@cowtowncoder
Copy link
Member

Nate @nbauernfeind can decide, but I am a bit concerned about one-off solutions that make Scala behavior differ from Java one. If there was a new DeserializationFeature that would enable this, things would work better -- and you could even enable/disable it for specific property if/as needed.
Another concern I have is that this changes observed behavior, and while it may be that majority of users could like it, it's enough to have a few users whose code breaks (or who have different preferences for handling) to make maintainers life much harder.

@SiliconMeeple
Copy link
Contributor Author

I can't speak for everyone, but one of our motivations for using Scala is being able to handle potentially-missing fields in more principled ways - a library adds scala support but will by default deserialise fields to null is quite surprising.

Is adding a new DeserializationFeature possible? It doesn't look like there are any language specific Features in there at the moment, and it can't be added in this module safely, as features need to claim a bit in the DeserializationConfig._deserFeatures int, which is currently done by ordinal in the DeserializationFeature enum.

@cowtowncoder
Copy link
Member

@HolyHaddock Adding DeserializationFeatures needs to happen in jackson-databind, modules can not add them on their own; this is what I'd suggest. While features should not be language/lib specific, ability to deser missing and/or null Collections into empty ones has been requested for Java and Kotlin too as well I think, so there'd be no need to label or make this Scala-only. There may be challenges in implementations elsewhere, and sometimes features are de facto limited to some langs/frameworks.

@SiliconMeeple
Copy link
Contributor Author

Looking at FasterXML/jackson-databind#347, it looks like @tadhgpearson made some progress on a spec, some tests and an implementation. Doesn't look like they pushed anything to their fork - is their work available anywhere to build off?

@cowtowncoder
Copy link
Member

@HolyHaddock I do not see an open PR for that unfortunately. Thank you for linking that issue.

@cowtowncoder
Copy link
Member

I think this:

FasterXML/jackson-databind#1402

could solve this issue, as long as Scala deserializers for collection(-like) types implement getEmptyValue(ctxt) to return proper empty collection.

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

Successfully merging this pull request may close these issues.

2 participants