-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
null-handling ignored #437
Comments
@cowtowncoder any update on this? |
No, I have not had time to look into this further unfortunately. |
Ok. Looking at this test case: it is actually working as expected. |
@cowtowncoder thanks for your answer. My problem is that, since we are using Jackson dataformats to handle at the same time JSON, YAML and XML payloads for REST, the same exact test case above works as expected with JSON and YAML in 2.12.1-SNAPSHOT but fails as described with XML. Could you suggest how to change or extend / override something into |
But could you just disable Other than that I think I would need to understanding something more about use case: combination of settings is bit incosistent. |
@cowtowncoder the following code: XML_MAPPER = new XmlMapper();
XML_MAPPER.configOverride(List.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
XML_MAPPER.configOverride(Set.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
XML_MAPPER.configOverride(Map.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
AnyObjectCR original = new AnyObjectCR();
original.setName("newPrinter");
original.setType("PRINTER");
original.getPlainAttrs().add(new Attr.Builder("location").value("new").build());
StringWriter writer = new StringWriter();
objectMapper().writeValue(writer, original);
AnyObjectCR actual = objectMapper().readValue(writer.toString(), AnyObjectCR.class);
assertEquals(original, actual); is throwing the following exception:
FYI, the definition of AnyObjectCR The same test code works fine with At the moment, unfortunately, I am in the situation where I have 1 XML test failure in case |
I would need a reproduction with input, ideally trimmed down to as small an example as possible. |
@cowtowncoder thanks for re-opening this issue; I've setup the reproducing sample at https://github.com/ilgrosso/jackson-dataformat-xml-437 The code is using 2.12.1-SNAPSHOT by default. As you can see, while the two test cases provided work fine with JSON and YAML, I did override for XML to show how enabling or disabling |
@ilgrosso When I clone the project, run with JDK 11, all tests pass? |
@cowtowncoder yes, the tests are passing on purpose: the cases for XML in fact are set to assert alternate failures. |
@ilgrosso I must be slow here: how do I need to modify tests to fail? |
@cowtowncoder sorry I thought to make the problem clearer this way... Take the first XML case, e.g. when Same happens with the second test case, e.g. when The test cases defined by superclass are run unchanged with JSON and YAML. |
I don't really get it: why would a test assert that the wrong thing happens? It would be easier to show expected behavior and then I can see what happens instead. Be that as it may, I think I get the intent now. |
It looks like you are comparing serializing a Cases are not equivalent, however: in root case, It seems to me that the issue is with I suspect there may be a change in String value handling from 2.11, regarding nullability. But I think is where further isolating test difference would be useful -- to see exactly what different do you see between 2.11 and 2.12. |
@cowtowncoder sorry for the confusion. I have updated the test project, hopefully to make it simpler and more consistent. After pulling, if you run it via
you get the following test failures:
As you can see from test code, the
I hope I was able to make clear how setting Finally, I have also added a Maven profile to run the same test suite against Jackson 2.11.4; if you run the project via
all tests are passing. Thanks again for your support. |
Thank you for updates. I will see if that helps me figure out what is the difference and whether change is something that needs to be fixed or something to be documented. |
At this point this test unfortunately only validates that the behavior with 2.12 differs from what your use case (based on 2.11) expects. For example: when serializing an empty |
Thanks for your answers; two questions related to this last point:
|
Documentation of
so it changes underlying token stream to infer concept of But at this point I do not think I still do not see any specific change that is suggested and will now close the issue. A new issue may be filed with specific aspect of handling of 2.12.0 that appears wrong. Difference in behavior between 2.11 and 2.12 is not sufficient. |
Ok, thanks for pointing out the Javadoc for Just to summarize, what I am experiencing now is that, with 2.12.1-SNAPSHOT, the feature enabled and the settings as explained above, this: <ArrayList/> is deserialized as <Root><pojos/></Root> is deserialized as an empty list. FTR, this: <ArrayList></ArrayList> is also deserialized an empty list. Hence, my current goal is to set things so that an empty collection (possibly, only when root element) is serialized as in the last case rather than in the first one. |
FYI with these settings all is passing now, both with 2.11 and 2.12.1-SNAPSHOT: https://github.com/ilgrosso/jackson-dataformat-xml-437/blob/main/src/test/java/net/tirasa/test/XMLTest.java#L23-L39 |
For what it is worth, empty element like I hope it is now possible to get things to work in a usable way: unfortunately the full combination of various aspects is not easy to reason about and it can be frustrating to find a good combination. Especially when attempting to make things work the same way against different versions. I am planning to release |
With 2.12.1-SNAPSHOT the following code:
fails with message
I have verified that serialization produces
<ArrayList/>
The text was updated successfully, but these errors were encountered: