Merge pull request #12402 from anuragkumawat/JAVA-12710
JAVA-12710 Look into XML Serialization and Deserialization with Jackson article
This commit is contained in:
commit
5277307f5b
|
@ -48,8 +48,7 @@ public class XMLSerializeDeserializeUnitTest {
|
|||
public void whenJavaGotFromXmlFile_thenCorrect() throws IOException {
|
||||
File file = new File("src/test/resources/simple_bean.xml");
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
String xml = inputStreamToString(new FileInputStream(file));
|
||||
SimpleBean value = xmlMapper.readValue(xml, SimpleBean.class);
|
||||
SimpleBean value = xmlMapper.readValue(file, SimpleBean.class);
|
||||
assertTrue(value.getX() == 1 && value.getY() == 2);
|
||||
}
|
||||
|
||||
|
@ -122,19 +121,6 @@ public class XMLSerializeDeserializeUnitTest {
|
|||
xmlMapper.writeValue(byteArrayOutputStream, person);
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue