Created
April 2, 2012 18:07
-
-
Save survivant/2285866 to your computer and use it in GitHub Desktop.
Jacskson-xml deserialize List problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.options; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
public class Main { | |
@JsonProperty("com.test.options") | |
public Options options; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.options; | |
public class Option { | |
public String name; | |
public String value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.options; | |
import java.util.List; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
public class Options { | |
@JsonProperty("option") | |
public List<Option> option; | |
//public String option; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<main> | |
<com.test.options> | |
<option name="icon1">/image1.png</option> | |
<option name="icon2">/image2.png</option> | |
</com.test.options> | |
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.options; | |
import java.io.File; | |
import com.fasterxml.jackson.databind.DeserializationFeature; | |
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/options.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