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
Allow JsonDeserializer to provide default value for "missing" properties #618
Comments
(Once this issue is closed, it may make sense to re-open the above issue) |
I tried really hard to support this using existing features like injectables, default "null" values, and so on, but they have pretty inconsistent behavior under common cases like creator vs field properties. Even addressing those still leaves a couple ambiguous cases though. I ended up side-stepping them and just using some fairly invasive wrapping/delegating deserializers and doing full TreeNode parsing. It is more expensive but those use cases did not involve frequent object ser/deser -- mostly configuration type stuff. The best I could come up with for maintaining streaming (no full TreeNode parsing) with reasonable performance was passing around a bit field indexed by property id that is toggled whenever a property is found and deserialized. A single primitive long, for instance, could track up to 64 fields that are either required or have special defaults, and would certainly have negligible overhead... but then you have an awkward, hard coded limit so might be worth abstracting anyway. It wasn't really possible to do that from the APIs made available for customization though. Or at least not without being even more incompatible with other components. |
FWTW, Jackson 2.6 actually does support injection of default values for Creator properties. |
This came up in https://github.com/FasterXML/jackson-datatype-jdk8/issues/2
When deserializing a bean containing
Optional<T>
fields, the valueOptional.empty()
makes more sense than filling innull
for properties that are entirely missing from the JSON.The text was updated successfully, but these errors were encountered: