Skip to content

Instantly share code, notes, and snippets.

@survivant
Created April 10, 2012 12:42
Show Gist options
  • Save survivant/2351109 to your computer and use it in GitHub Desktop.
Save survivant/2351109 to your computer and use it in GitHub Desktop.
Unrecognized field ""
<?xml version="1.0" encoding="UTF-8"?>
<main>
<com.test.stack name="stack1">
<com.test.stack.slot height="0" id="0" name="slot0" width="0">+/null/this is a long string</com.test.stack.slot>
</com.test.stack>
</main>
package com.test.stack;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Main {
@JsonProperty("com.test.stack")
public Stack stack;
}
package com.test.stack;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
//@JsonIgnoreProperties(ignoreUnknown = true) //Need to have that I'll get an exception
public class Slot {
@JsonProperty("name")
public String name;
@JsonProperty("id")
public String id;
@JsonProperty("height")
public String height;
@JsonProperty("width")
public String width;
@JacksonXmlText
public String value;
}
package com.test.stack;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Stack {
public String name;
@JsonProperty("com.test.stack.slot")
public Slot slot;
}
package com.test.stack;
import java.io.File;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class TestImporter {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String filename = "resources/emptyField.xml";
ObjectMapper xmlMapper = new XmlMapper();
//xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
//xmlMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true);
Main pojo = xmlMapper.readValue(new File(filename), Main.class);
System.out.println(pojo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment