JAVA-12710 Look into XML Serialization and Deserialization with Jackson article

This commit is contained in:
anuragkumawat 2022-06-23 21:06:31 +05:30
parent 48b451fd70
commit cf932245aa
1 changed files with 1 additions and 15 deletions

View File

@ -48,8 +48,7 @@ public class XMLSerializeDeserializeUnitTest {
public void whenJavaGotFromXmlFile_thenCorrect() throws IOException { public void whenJavaGotFromXmlFile_thenCorrect() throws IOException {
File file = new File("src/test/resources/simple_bean.xml"); File file = new File("src/test/resources/simple_bean.xml");
XmlMapper xmlMapper = new XmlMapper(); XmlMapper xmlMapper = new XmlMapper();
String xml = inputStreamToString(new FileInputStream(file)); SimpleBean value = xmlMapper.readValue(file, SimpleBean.class);
SimpleBean value = xmlMapper.readValue(xml, SimpleBean.class);
assertTrue(value.getX() == 1 && value.getY() == 2); assertTrue(value.getX() == 1 && value.getY() == 2);
} }
@ -122,19 +121,6 @@ public class XMLSerializeDeserializeUnitTest {
xmlMapper.writeValue(byteArrayOutputStream, person); xmlMapper.writeValue(byteArrayOutputStream, person);
assertEquals(expectedXml, byteArrayOutputStream.toString()); assertEquals(expectedXml, byteArrayOutputStream.toString());
} }
private static String inputStreamToString(InputStream is) throws IOException {
BufferedReader br;
StringBuilder sb = new StringBuilder();
String line;
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
return sb.toString();
}
} }
class SimpleBean { class SimpleBean {