Merge pull request #3818 from khatwaniNikhil/BAEL-1284

Changes for handling capitalised xml elements
This commit is contained in:
Loredana Crusoveanu 2018-03-15 11:41:04 +02:00 committed by GitHub
commit 4d089155f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 0 deletions

View File

@ -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("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>",
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;
}
}