Entity { @JsonAnySetter public void setAttributes(String key, Attribute attribute) { if (attributes == null) { attributes = new HashMap<String, Attribute>(); } attributes.put(key, attribute); } Entity();  Entity(String id, String type);  Entity(String id, String type, Map<String, Attribute> attributes); String getId(); void setId(String id); String getType(); void setType(String type); @JsonAnyGetter Map<String, Attribute> getAttributes(); @JsonAnySetter void setAttributes(String key, Attribute attribute); @JsonIgnore void setAttributes(Map<String, Attribute> attributes);  }
@Test public void serializationEntityTest() throws JsonProcessingException { ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter()); Entity entity = new Entity("Bcn-Welt", "Room"); HashMap<String,Attribute> attributes = new HashMap<String, Attribute>(); Attribute tempAttribute = new Attribute(21.7); attributes.put("temperature", tempAttribute); Attribute humidityAttribute = new Attribute(60); attributes.put("humidity", humidityAttribute); entity.setAttributes(attributes); String json = writer.writeValueAsString(entity); String jsonString = "{\n" + " \"id\" : \"Bcn-Welt\",\n" + " \"type\" : \"Room\",\n" + " \"temperature\" : {\n" + " \"value\" : 21.7,\n" + " \"metadata\" : { }\n" + " },\n" + " \"humidity\" : {\n" + " \"value\" : 60,\n" + " \"metadata\" : { }\n" + " }\n" + "}"; assertEquals(jsonString, json); }