Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / base / database / JsonMapperBase.java
1 /*********************************************************************************
2  *  Copyright © 2015, highstreet technologies GmbH
3  *  All rights reserved!
4  *
5  *  http://www.highstreet-technologies.com/
6  *
7  *  The reproduction, transmission or use of this document or its contents is not
8  *  permitted without express written authority. Offenders will be liable for
9  *  damages. All rights, including rights created by patent grant or registration
10  *  of a utility model or design, are reserved. Technical modifications possible.
11  *  Technical specifications and features are binding only insofar as they are
12  *  specifically and expressly agreed upon in a written contract.
13  *
14  *  @author: Martin Skorupski [martin@skorupski.de]
15  *********************************************************************************/
16 package org.opendaylight.mwtn.base.database;
17
18 import java.io.IOException;
19 import java.io.StringWriter;
20 import java.util.List;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
26 import com.fasterxml.jackson.annotation.PropertyAccessor;
27 import com.fasterxml.jackson.core.JsonGenerationException;
28 import com.fasterxml.jackson.core.JsonGenerator.Feature;
29 import com.fasterxml.jackson.databind.DeserializationFeature;
30 import com.fasterxml.jackson.databind.JsonMappingException;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.SerializationFeature;
33
34 /**
35  * This class is used to define default for JSON Serialization and Deserialization for the project at a single place
36  */
37 public class JsonMapperBase extends ObjectMapper {
38
39     private static final long serialVersionUID = 1L;
40     private static final Logger LOG = LoggerFactory.getLogger(JsonMapperBase.class);
41
42     public JsonMapperBase() {
43
44         setVisibility(PropertyAccessor.ALL, Visibility.NONE);
45         setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
46
47         // Deserialization
48         configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
49         configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
50
51         // Serialization
52         configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
53         getFactory().configure(Feature.ESCAPE_NON_ASCII, true);
54     }
55
56
57     public String objectToJson( Object object ) {
58         String res = null;
59
60         try {
61
62             StringWriter stringEmp = new StringWriter();
63             writeValue(stringEmp, object);
64             res = stringEmp.toString();
65             stringEmp.close();
66
67         } catch (JsonGenerationException e) {
68             LOG.debug(e.toString());
69         } catch (JsonMappingException e) {
70             LOG.debug(e.toString());
71         } catch (IOException e) {
72             LOG.debug(e.toString());
73         } catch (Exception e) {
74             LOG.debug(e.toString());
75         }
76
77         return res;
78     }
79
80     public String objectListToJson( List<? extends Object> objectList ) {
81         String res = null;
82
83         try {
84
85             StringWriter stringEmp = new StringWriter();
86             writeValue(stringEmp, objectList);
87             res = stringEmp.toString();
88             stringEmp.close();
89
90         } catch (JsonGenerationException e) {
91             LOG.debug(e.toString());
92         } catch (JsonMappingException e) {
93             LOG.debug(e.toString());
94         } catch (IOException e) {
95             LOG.debug(e.toString());
96         } catch (Exception e) {
97             LOG.debug(e.toString());
98         }
99
100         return res;
101     }
102
103 }