New API for GNPy
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / gnpy / consumer / ResultDeserializer.java
1 /*
2  * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.pce.gnpy.consumer;
9
10 import com.fasterxml.jackson.core.JsonParser;
11 import com.fasterxml.jackson.databind.DeserializationContext;
12 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
13 import java.io.IOException;
14 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
15 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.Result;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22
23 //This class is a temporary workaround while waiting jackson
24 //support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
25 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "temporary class")
26 public class ResultDeserializer extends StdDeserializer<Result> {
27
28     private static final Logger LOG = LoggerFactory.getLogger(ResultDeserializer.class);
29     private static final long serialVersionUID = 1L;
30     private JsonStringConverter<Result> converter;
31     private YangInstanceIdentifier yangId;
32
33     public ResultDeserializer(JsonStringConverter<Result> converter) {
34         super(Result.class);
35         this.converter = converter;
36         QName pathQname = Result.QNAME;
37         LOG.info("QName of the first result class {}", pathQname);
38         yangId = YangInstanceIdentifier.of(pathQname);
39     }
40
41     @Override
42     public Result deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
43         return converter.createDataObjectFromJsonString(yangId,parser.readValueAsTree().toString(),
44             JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
45     }
46
47 }