diff --git a/jackson/src/test/java/com/baeldung/jackson/xmlToJson/XmlToJsonUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/xmlToJson/XmlToJsonUnitTest.java index 295bb9d6e8..6329a8ed2f 100644 --- a/jackson/src/test/java/com/baeldung/jackson/xmlToJson/XmlToJsonUnitTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/xmlToJson/XmlToJsonUnitTest.java @@ -1,7 +1,5 @@ package com.baeldung.jackson.xmlToJson; - -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; @@ -14,43 +12,32 @@ import java.io.IOException; public class XmlToJsonUnitTest { @Test - public void givenAnXML_whenUseDataBidingToConvertToJSON_thenReturnDataOK() { + public void givenAnXML_whenUseDataBidingToConvertToJSON_thenReturnDataOK() throws IOException{ String flowerXML = "PoppyRED9"; - try { - XmlMapper xmlMapper = new XmlMapper(); - Flower poppy = xmlMapper.readValue(flowerXML, Flower.class); + XmlMapper xmlMapper = new XmlMapper(); + Flower poppy = xmlMapper.readValue(flowerXML, Flower.class); - assertEquals(poppy.getName(), "Poppy"); - assertEquals(poppy.getColor(), Color.RED); - assertEquals(poppy.getPetals(), new Integer(9)); + assertEquals(poppy.getName(), "Poppy"); + assertEquals(poppy.getColor(), Color.RED); + assertEquals(poppy.getPetals(), new Integer(9)); - ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(poppy); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(poppy); - assertEquals(json, "{\"name\":\"Poppy\",\"color\":\"RED\",\"petals\":9}"); - System.out.println(json); - } catch(IOException e) { - e.printStackTrace(); - } + assertEquals(json, "{\"name\":\"Poppy\",\"color\":\"RED\",\"petals\":9}"); } @Test - public void givenAnXML_whenUseATreeConvertToJSON_thenReturnDataOK() { + public void givenAnXML_whenUseATreeConvertToJSON_thenReturnDataOK() throws IOException { String flowerXML = "PoppyRED9"; - try { - XmlMapper xmlMapper = new XmlMapper(); - JsonNode node = xmlMapper.readTree(flowerXML.getBytes()); + XmlMapper xmlMapper = new XmlMapper(); + JsonNode node = xmlMapper.readTree(flowerXML.getBytes()); - ObjectMapper jsonMapper = new ObjectMapper(); - String json = jsonMapper.writeValueAsString(node); + ObjectMapper jsonMapper = new ObjectMapper(); + String json = jsonMapper.writeValueAsString(node); - System.out.println(json); - - assertEquals(json, "{\"name\":\"Poppy\",\"color\":\"RED\",\"petals\":\"9\"}"); - } catch(IOException e) { - e.printStackTrace(); - } + assertEquals(json, "{\"name\":\"Poppy\",\"color\":\"RED\",\"petals\":\"9\"}"); } }