finish alto-manager and related alto-commons code
[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 java.io.IOException;
4
5 import com.fasterxml.jackson.annotation.JsonInclude.Include;
6 import com.fasterxml.jackson.databind.DeserializationFeature;
7 import com.fasterxml.jackson.databind.ObjectMapper;
8
9 public class ModelJSONMapper {
10
11     private ObjectMapper mapper = new ObjectMapper()
12                             .setSerializationInclusion(Include.NON_DEFAULT)
13                             .disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
14
15     public ModelNetworkMap asNetworkMap(String json) throws Exception {
16       return mapper.readValue(json, ModelNetworkMap.class);
17     }
18     
19     public ModelCostMap asCostMap(String json) throws Exception {
20       return mapper.readValue(json, ModelCostMap.class);
21     }
22     
23     public ModelEndpointPropertyMap asEndpointPropMap(String json) throws Exception {
24       return mapper.readValue(json, ModelEndpointPropertyMap.class);
25     }
26
27     public ModelEndpoint asModelEndpoint(String json) throws IOException {
28       return mapper.readValue(json, ModelEndpoint.class);
29     }
30
31     public String asJSON(Object obj) throws Exception {
32       return mapper.writeValueAsString(obj);
33     }
34 }