I am hoping someone can point out what is escaping me. This is my first attempt to deserialize XML. Here is a cut-down of my problem.
Thanks,
Harold
I have these Java classes
@JacksonXmlRootElement(localName = "migrationCompatibility")
public class MigrationCompatibility {
@JsonCreator public MigrationCompatibility() {}
@JacksonXmlProperty(localName = "products")
@JacksonXmlElementWrapper(useWrapping = false)
public Products[] products;
public Products[] getproducts() {
return products;
}
public void setproducts(Products[] products) {
this.products = products;
}
}
public class Products {
@JsonCreator public Products() {}
@JacksonXmlProperty(localName = "foo")
public String foo = "hi";
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
}
And this code to test them.
Products products = new Products();
Products[] productsList = new Products[1];
productsList[0] = products;
MigrationCompatibility migrationCompatibility1 = new MigrationCompatibility();
migrationCompatibility1.setproducts(productsList);
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.writeValue(new File("J:\\stuff.xml"), migrationCompatibility1);
MigrationCompatibility migrationCompatibility = xmlMapper.readValue(new File("J:\\stuff.xml"), MigrationCompatibility.class);
System.out.println(migrationCompatibility);
The serialization works as expected and produces the xml as expected. cat stuff.xml
<migrationCompatibility><products><foo>hi</foo></products></migrationCompatibility>
However the complementary call deserialize above results in an exception. It seems it does not recognize the tag, but I cannot not figure out why.
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "products" (...), not marked as ignorable (0 known properties: ]) at [Source: J:\stuff.xml; line: 1, column: 35]
No comments:
Post a Comment