diff --git a/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java index adb0fe0413..0e2a52e75c 100644 --- a/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java @@ -14,6 +14,7 @@ import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.annotation.JsonProperty; public class XMLSerializeDeserializeUnitTest { @@ -48,6 +49,24 @@ public class XMLSerializeDeserializeUnitTest { assertTrue(value.getX() == 1 && value.getY() == 2); } + @Test + public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException { + XmlMapper xmlMapper = new XmlMapper(); + SimpleBeanForCapitalizedFields value = xmlMapper. + readValue("12", + SimpleBeanForCapitalizedFields.class); + assertTrue(value.getX() == 1 && value.getY() == 2); + } + + @Test + public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException { + XmlMapper xmlMapper = new XmlMapper(); + xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"), + new SimpleBeanForCapitalizedFields()); + File file = new File("target/simple_bean_capitalized.xml"); + assertNotNull(file); + } + private static String inputStreamToString(InputStream is) throws IOException { BufferedReader br; StringBuilder sb = new StringBuilder(); @@ -83,3 +102,25 @@ class SimpleBean { } } + +class SimpleBeanForCapitalizedFields { + @JsonProperty("X") + private int x = 1; + private int y = 2; + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } +} \ No newline at end of file