@Test public void iaaSMessageFromJSONtoObjectTest() { IaaSMessage im = Converter.iaasMessageFromJSONToObject(json); assertEquals("name", im.getName()); assertEquals("units", im.getUnits()); assertEquals(22l, im.getTimestamp()); assertEquals(0.1, im.getValue(), 0.00001); im = Converter.iaasMessageFromJSONToObject("adadafa"); assertEquals(im, null); }
public static IaaSMessage iaasMessageFromJSONToObject(String json) { try { JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {IaaSMessage.class}, null); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); StreamSource jsonSource = new StreamSource(new StringReader(json)); IaaSMessage im = unmarshaller.unmarshal(jsonSource, IaaSMessage.class).getValue(); return im; } catch(Exception exception) { logger.error(exception.getMessage()); return null; } }
Converter { public static IaaSMessage iaasMessageFromJSONToObject(String json) { try { JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {IaaSMessage.class}, null); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); StreamSource jsonSource = new StreamSource(new StringReader(json)); IaaSMessage im = unmarshaller.unmarshal(jsonSource, IaaSMessage.class).getValue(); return im; } catch(Exception exception) { logger.error(exception.getMessage()); return null; } } }
Converter { public static IaaSMessage iaasMessageFromJSONToObject(String json) { try { JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {IaaSMessage.class}, null); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); StreamSource jsonSource = new StreamSource(new StringReader(json)); IaaSMessage im = unmarshaller.unmarshal(jsonSource, IaaSMessage.class).getValue(); return im; } catch(Exception exception) { logger.error(exception.getMessage()); return null; } }  }
Converter { public static IaaSMessage iaasMessageFromJSONToObject(String json) { try { JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {IaaSMessage.class}, null); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); StreamSource jsonSource = new StreamSource(new StringReader(json)); IaaSMessage im = unmarshaller.unmarshal(jsonSource, IaaSMessage.class).getValue(); return im; } catch(Exception exception) { logger.error(exception.getMessage()); return null; } }  static IaaSMessage iaasMessageFromJSONToObject(String json); static String iaasMessageToJSON(IaaSMessage im); }
Converter { public static IaaSMessage iaasMessageFromJSONToObject(String json) { try { JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {IaaSMessage.class}, null); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); StreamSource jsonSource = new StreamSource(new StringReader(json)); IaaSMessage im = unmarshaller.unmarshal(jsonSource, IaaSMessage.class).getValue(); return im; } catch(Exception exception) { logger.error(exception.getMessage()); return null; } }  static IaaSMessage iaasMessageFromJSONToObject(String json); static String iaasMessageToJSON(IaaSMessage im);  }