Update license date and text
[aai/champ.git] / champ-service / src / main / java / org / onap / champ / entity / ChampObjectDeserializer.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  */
21 package org.onap.champ.entity;
22
23 import java.io.IOException;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.onap.aai.champcore.model.ChampObject;
28
29 import com.fasterxml.jackson.core.JsonParser;
30 import com.fasterxml.jackson.core.JsonProcessingException;
31 import com.fasterxml.jackson.databind.DeserializationContext;
32 import com.fasterxml.jackson.databind.JsonNode;
33 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
34
35 public class ChampObjectDeserializer extends StdDeserializer<ChampObject> {
36         
37         private static final long serialVersionUID = -3625275249560680339L;
38
39         public ChampObjectDeserializer() {
40                 this(null);
41         }
42         
43         protected ChampObjectDeserializer(Class<ChampObject> t) {
44                 super(t);
45         }
46         
47         public ChampObject deserialize(JsonParser jparser, DeserializationContext dctx)
48                         throws IOException, JsonProcessingException {
49                 
50                 JsonNode node = jparser.getCodec().readTree(jparser);
51                 JsonNode type = node.get("type");
52                 JsonNode key = node.get("key");
53                 Map<String, Object> props = new HashMap<>();
54                 JsonNode propNode = node.get("properties");
55                 propNode.fields().forEachRemaining((x)->props.put(x.getKey(), x.getValue().asText()));
56                 
57                 ChampObject.Builder builder = new ChampObject.Builder(type.asText()).properties(props);
58                 
59                 if(key != null){
60                         builder.key(key.asText());
61                 }
62                 
63                 return builder.build();
64         }
65
66 }