Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Add a feature in JaxbAnnotationIntrospector to define meaning of nillable=false as "JsonInclude.NON_EMPTY" #52

Closed
cowtowncoder opened this issue Jan 4, 2016 · 1 comment
Milestone

Comments

@cowtowncoder
Copy link
Member

(see #48, #49 for background)

Meaning of nillable property of @XmlElement and @XmlElements comes from XML Schema, and defines whether it is legal/mandatory to suppress writing out of empty collections. For Jackson this can be achieved by returning different inclusion criteria for a property annotated with one of these annotations.

For a longer discussion, see the original change #39 (for Jackson 2.5.1), which covers many aspects of handling.

Since I am not convinced that the change suggested in #48 / #49 is safe (although perhaps returning Include.NON_NULL might be acceptable, more so than NON_EMPTY), I will add a setting with which one can specifically define which JsonInclude.Incude value to use for nillable = false; default being null (meaning none). To do what #48 asks, Include.NON_EMPTY should be returned, or possibly Include.NON_NULL.

@cowtowncoder
Copy link
Member Author

Adding method setNonNillableInclusion in JaxbAnnotationIntrospector, as well as JaxbAnnotationModule; either way, needs to be called before introspector is registered with ObjectMapper.

To implement behavior desired for #48 / #49, should set value either as JsonInclude.Include.NON_NULL or JsonInclude.Include.NON_EMPTY, depending on exact desired semantics: former will not write property if value is strictly Java null; latter if it is either Java null OR value defined as empty, most commonly Collection or Map with size of 0.

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

No branches or pull requests

1 participant