-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
RFE: per-property/per-class unwrapped de/serialization of single-element array/List/Set/Queue/Collection #611
Comments
I think this makes sense; many/most Jackson features have both general defaults, and local overrides, sometimes even two levels (per-class, per-property). One question here is the annotation to use. Possible alternative could be to add a new property for One more thought is whether there's need for actual Jackson LD datatype module. While it might seem like an overkill for just this feature, if there are related things that would need tweaks or additions, I would prefer building new stuff outside of the core databind. |
A Jackson LD module would definitely be of interest. I'm using Jackson to output JSON-LD as well and we've had to use a few hacks to get it to work smoothly. |
I'd prioritize the annotation first... so it can be used as quick solution, although cannot parse full JSON-LD. @ansell develops https://github.com/jsonld-java/jsonld-java project which uses Jackson 2.3.3 currently. I for one would be happy if there'd be a JSON-LD module for Jackson (easy to use like JodaModule) that supports "native" binding of JSON-LD structure. For example, instead of binding field names... we bind Linked Data names (i.e. http://schema.org/offers). @JsonTypeInfo will be enhanced to support Linked Data classes. Same goes for representing URIs, enums, etc. But this would be a major effort... |
My point here is that if annotation did not have to be added in core Jackson (annotations or databind), that might be preferable regardless. Adding a module & project is easy, so there isn't much cost from our side. Having said that, I am ok with this as a databind feature. I am just worried about simple one-off annotations, and would want to limit number of core annotations. |
This was a feature I had to cut when I switched over to jackson for most of the back-end processing. However, during the time I supported per property overrides, I never ran into a case where allowing coercion during deserialization but always writing back out as arrays was undesirable behavior. I was considering making that the default anyway. That seems to be the behavior you are suggesting in your example, except that now you would be able to enforce stricter parsing on other fields. Maybe I am undervaluing deserialization strictness, but that doesn't seem like a huge gain at first glance. FWIW, I configured this setting as a boolean annotation field named |
@tea-dragon One possibility would, in fact, be to add support via |
Starting with |
This was actually implemented via FasterXML/jackson-annotations#43 and I think specifically with If features are missing, please re-file a new issue, as that makes it easier to keep track of work and related versions. |
This builds upon the work in https://jira.codehaus.org/browse/JACKSON-805
A feature to do this on a per-property or per-class (with inheritance) basis.
[JSON-LD|http://www.w3.org/TR/json-ld/] which is a W3C Recommendation, uses this convention where a singular property can be turned into array (retaining the original name) in order to have multiple cardinality.
However, some properties, like http://schema.org/offers are always rendered as array.
While the proper way to handle such cases is a full-blown JSON-LD processor (JSON-LD has lots more features and is very flexible), for common use cases people might just want to use Jackson to read/write JSON-LD, and having this capability will be good.
An annotation is required, probably
@JsonCollectionAsScalar
(or@JsonScalar
? or@JsonSingleElement
?), with two fields:serialize=false
in order to make it much easier (albeit longer JSON path) for naive clients to read, since the JSON will have a rigid schema.If boolean is ambiguous then can also use enum.
Note that behavior for nested collection is undefined (and probably should be an error), so the contents of collection must be either primitive or a non-collection object. (note that some objects may be
Iterable
, which should be okay, still treated as JSON object)The text was updated successfully, but these errors were encountered: