A great update on the alto-commons implementation.
[alto.git] / alto-commons / src / main / java / org / opendaylight / alto / commons / types / model150404 / ModelJSONMapper.java
1 package org.opendaylight.alto.commons.types.model150404;
2
3 import com.fasterxml.jackson.annotation.JsonInclude.Include;
4 import com.fasterxml.jackson.databind.DeserializationFeature;
5 import com.fasterxml.jackson.databind.ObjectMapper;
6
7 public class ModelJSONMapper {
8
9     private ObjectMapper mapper = new ObjectMapper()
10                             .setSerializationInclusion(Include.NON_DEFAULT)
11                             .disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
12
13     public ModelNetworkMap asNetworkMap(String json) throws Exception {
14         return mapper.readValue(json, ModelNetworkMap.class);
15     }
16
17     public String asJSON(Object obj) throws Exception {
18         return mapper.writeValueAsString(obj);
19     }
20 }