@Test public void getJSONEnergyConsumedTest() throws Exception { EnergyCosumed energyConsumed = new EnergyCosumed(); energyConsumed.setAppId("appId"); energyConsumed.setInstanceId("instaceId"); Data data = new Data(); data.setEnd("end"); data.setStart("start"); data.setPower("power"); energyConsumed.setData(data); String energyConsumedJson = Parser.getJSONEnergyConsumed(energyConsumed); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); mapper.setSerializationInclusion(Inclusion.NON_NULL); EnergyCosumed energyCosumedFromJson = mapper.readValue(energyConsumedJson, EnergyCosumed.class); assertEquals("appId", energyCosumedFromJson.getAppId()); assertEquals("instaceId", energyCosumedFromJson.getInstanceId()); assertEquals("end", energyCosumedFromJson.getData().getEnd()); assertEquals("start", energyCosumedFromJson.getData().getStart()); assertEquals("power", energyCosumedFromJson.getData().getPower()); }
public static String getJSONEnergyConsumed(EnergyCosumed energyCosumed) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); return mapper.writeValueAsString(energyCosumed); }
Parser { public static String getJSONEnergyConsumed(EnergyCosumed energyCosumed) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); return mapper.writeValueAsString(energyCosumed); } }
Parser { public static String getJSONEnergyConsumed(EnergyCosumed energyCosumed) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); return mapper.writeValueAsString(energyCosumed); }  }
Parser { public static String getJSONEnergyConsumed(EnergyCosumed energyCosumed) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); return mapper.writeValueAsString(energyCosumed); }  static String getJSONEnergyConsumed(EnergyCosumed energyCosumed); }
Parser { public static String getJSONEnergyConsumed(EnergyCosumed energyCosumed) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); return mapper.writeValueAsString(energyCosumed); }  static String getJSONEnergyConsumed(EnergyCosumed energyCosumed);  }