2 * Copyright © 2021 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.pce.gnpy.consumer;
10 import com.fasterxml.jackson.core.JsonGenerator;
11 import com.fasterxml.jackson.databind.SerializerProvider;
12 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
13 import java.io.IOException;
14 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
15 import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 //This class is a temporary workaround while waiting jackson
22 //support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
23 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "temporary class")
25 public class RequestSerializer extends StdSerializer<Request> {
26 private static final long serialVersionUID = 1L;
27 private static final Logger LOG = LoggerFactory.getLogger(RequestSerializer.class);
28 private JsonStringConverter<Request> converter;
29 private InstanceIdentifier<Request> idRequest = InstanceIdentifier.builder(Request.class).build();
31 public RequestSerializer(JsonStringConverter<Request> converter) {
33 this.converter = converter;
37 public void serialize(Request value, JsonGenerator gen, SerializerProvider provider) throws IOException {
38 String requestStr = this.converter
39 .createJsonStringFromDataObject(this.idRequest, value,
40 JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
41 requestStr = requestStr.replace("gnpy-network-topology:", "");
42 LOG.info("Serialized request {}", requestStr);
43 gen.writeRaw(requestStr);