2 * ============LICENSE_START==========================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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============================================
21 package org.onap.champ.entity;
23 import java.io.IOException;
24 import java.util.HashMap;
26 import com.fasterxml.jackson.core.JsonParser;
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.DeserializationContext;
29 import com.fasterxml.jackson.databind.JsonNode;
30 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
32 import org.onap.aai.champcore.model.ChampObject;
33 import org.onap.aai.champcore.model.ChampRelationship;
35 public class ChampRelationshipDeserializer extends StdDeserializer<ChampRelationship> {
37 private static final long serialVersionUID = -3625275249560680339L;
39 public ChampRelationshipDeserializer() {
43 protected ChampRelationshipDeserializer(Class<ChampRelationship> t) {
47 public ChampRelationship deserialize(JsonParser jparser, DeserializationContext dctx)
48 throws IOException, JsonProcessingException {
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()));
57 JsonNode srcNode = node.get("source");
58 JsonNode targetNode = node.get("target");
60 ChampObject src = jparser.getCodec ().treeToValue ( srcNode, ChampObject.class );
61 ChampObject target = jparser.getCodec ().treeToValue ( targetNode, ChampObject.class );
63 ChampRelationship.Builder builder = new ChampRelationship.Builder(src, target, type.asText()).properties(props);
66 builder.key(key.asText());
69 return builder.build();