XmlImpl implements Xml { @Override public <T> String parse(T object) { try { return mapper().writeValueAsString(object); } catch (JsonProcessingException e) { log.error(e.getMessage(), e); return null; } }  @Override String parse(T object); @SuppressWarnings("unchecked") @Override T parse(String xml, Class<?> classType);  }
@Test public void parseStringToObjectWithXmlSpec() { Variable variable = new Variable(); variable.setId(20L); variable.setKey("Name"); variable.setValue("valueName"); String parse = xmlParser.parse(variable); assertNotNull(parse); assertEquals("<Variable><id>20</id><key>Name</key><value>valueName</value><environment/></Variable>", parse); }
@Test public void ignoreWhenNotExistField() { Variable variable = xmlParser.parse("<Variable><id>20</id><notExist>20</notExist><key>Name</key><value>valueName</value><environment/></Variable>", Variable.class); assertNotNull(variable); assertEquals(new Long(20), variable.getId()); }