You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
Hi. I have faced a minor issue when using JsonUnwrapped annotation together with a custom null value: null value is ignored when serializing nested objects. Here comes an example:
importcom.fasterxml.jackson.annotation.JsonUnwrapped;
importcom.fasterxml.jackson.core.JsonProcessingException;
importcom.fasterxml.jackson.dataformat.csv.CsvMapper;
importcom.fasterxml.jackson.dataformat.csv.CsvSchema;
classInner {
publicStringf1;
publicStringf2;
publicStringf3;
}
classOuter {
publicStringf1;
@JsonUnwrappedpublicInnerf2;
}
publicclassTest {
publicstaticvoidmain(Stringargs[]) throwsJsonProcessingException {
finalCsvMappermapper = newCsvMapper();
// Set null value to 'null'finalCsvSchemaschema = mapper.schemaFor(Outer.class).withNullValue("null");
// Create an object. All the fields are NULLsfinalOuterouter = newOuter();
// Serialize the object.// I would expect: null,null,null,null// I get: null,,,System.out.println(mapper.writer(schema).writeValueAsString(outer));
}
}
The text was updated successfully, but these errors were encountered:
I added a test to show what causes the problem, and noticed that Inner f2 was left as null.
This is why no writes for enclosing entries occurs: there is nothing to de-reference and in a way nothing to write (in JSON the whole entry would be ignored). So omission of "null" is because no writes exist.
You could solve the case here by initializing Inner to be an actual instance, if empty one.
However... this leads to question of what to do with "missing" values -- should those be written as null values, or just omitted? This question is more general than unwrapping (handling of which can not be changed much at any rate), since it is possible to omit writing of any columns: but if so, should filler value of null value be used or not?
My leaning is that filler should indeed be used, but based on past experience suspect that doing that may make some users unhappy (since at this point nothing is written, so there may be use cases where this difference between explicit null write vs missing write could work the way user wants).
So, at very least change to force "null" writing needs to get in 2.9 and not in earlier patches.
Whether a new property of CsvSchema is needed, or, possibly, CsvGenerator.Feature, I don't know. It would probably make more sense as CsvGenerator.Feature just to avoid feature creep for schemas.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi. I have faced a minor issue when using JsonUnwrapped annotation together with a custom null value: null value is ignored when serializing nested objects. Here comes an example:
The text was updated successfully, but these errors were encountered: