-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
defaultUseWrapper setting does not work when xsi:nil is used as attribute #372
Comments
I'm not sure if my issues is 100% related to this one, as it's more general than As @pablow91 mentioned, it "works" with @cowtowncoder I see that test cases where added #366 , but is there a corresponding issue? Is this the issue? Saw the note about not knowing when to look at straightening the Here's my write up to expand on what others have already mentioned It appears that when the I'm not the best with XML and maybe I'm misunderstanding Setup
Test Scenario Results
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<subObj1>
<x>test-x</x>
<y>test-y</y>
</subObj1>
<subobj2>
<z>test-z</z>
</subobj2>
</Test>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<subObj1>
<x>test-x</x>
<y xsi:nil="true" />
</subObj1>
<subobj2>
<z>test-z</z>
</subobj2>
</Test>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<subObj1>
<x>test-x</x>
<y>test-y</y>
</subObj1>
<subobj2>
<z xsi:nil="true" />
</subobj2>
</Test>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<subObj1>
<x xsi:nil="true" />
<y>test-y</y>
</subObj1>
<subobj2>
<z>test-z</z>
</subobj2>
</Test>
Test Programpackage com.test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
class TopObj {
public SubObj1 subObj1;
public SubObj2 subobj2;
@Override
public String toString() {
return "TopObj{" +
"subObj1=" + subObj1 +
", subobj2=" + subobj2 +
'}';
}
}
class SubObj1 {
public String x;
public String y;
@Override
public String
toString() {
return "SubObj1{" +
"x='" + x + '\'' +
", y='" + y + '\'' +
'}';
}
}
class SubObj2 {
public String z;
@Override
public String toString() {
return "SubObj{" +
"z='" + z + '\'' +
'}';
}
}
public class NilTester {
public static void main(String[] args) throws Exception {
System.out.println("1. Testing non nil XML");
testXML(XML_SUCCESS_DESER);
System.out.println("2. Testing nil at end of SubObj1, proving things work but all following values are null (subobj2)");
testXML(XML_MOVE_NIL_TO_END_OBJ_ONE_DESER);
System.out.println("3. Testing nil at end of SubObj2, proving things work fully when nil is only at the end");
testXML(XML_MOVE_NIL_TO_END_OBJ_TWO_DESER);
System.out.println("4. Testing nil at start of object, proving parsing crashes. Claims the next field is \"Unrecognized\"");
testXML(XML_FAIL_DESER);
}
private static void testXML(String xml) throws Exception {
System.out.println(xml);
TopObj topObj = mapper.readValue(xml, TopObj.class);
System.out.println("Result Obj: " + topObj.toString() + "\n");
}
/**
* No nils
*/
private static String XML_SUCCESS_DESER = String.join("\n",
"<Test xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
" <subObj1>",
" <x>test-x</x>",
" <y>test-y</y>",
" </subObj1>",
" <subobj2>",
" <z>test-z</z>",
" </subobj2>",
"</Test>"
);
/**
* Move {@code xsi:nil="true"} to last element in {@link SubObj1}, it works, but all following members in
* {@link SubObj2} are null
*/
private static String XML_MOVE_NIL_TO_END_OBJ_ONE_DESER = String.join("\n",
"<Test xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
" <subObj1>",
" <x>test-x</x>",
" <y xsi:nil=\"true\" />",
" </subObj1>",
" <subobj2>",
" <z>test-z</z>",
" </subobj2>",
"</Test>"
);
/**
* Move {@code xsi:nil="true"} to last element in {@link SubObj2}, it works as it's the last element to parse
*/
private static String XML_MOVE_NIL_TO_END_OBJ_TWO_DESER = String.join("\n",
"<Test xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
" <subObj1>",
" <x>test-x</x>",
" <y>test-y</y>",
" </subObj1>",
" <subobj2>",
" <z xsi:nil=\"true\" />",
" </subobj2>",
"</Test>"
);
/**
* Note {@code xsi:nil="true"} in {@link SubObj1#x}, crashing the deserialization of {@link SubObj1#y}
*/
private static String XML_FAIL_DESER = String.join("\n",
"<Test xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
" <subObj1>",
" <x xsi:nil=\"true\" />",
" <y>test-y</y>",
" </subObj1>",
" <subobj2>",
" <z>test-z</z>",
" </subobj2>",
"</Test>"
);
private static ObjectMapper mapper = new XmlMapper();
} |
Looks like my issue no longer occurs in version 2.10.2 |
There is an issue with deserilalizing collecions when one of the element contains
xsi:nil
attribuite and the default use wrapper is set to false.Code for reproducing the issue:
This code works in 2.9.10, but after upgrading to the 2.10.0 the code returns the exception:
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `maven.Item` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('two')
The text was updated successfully, but these errors were encountered: