Refactor NBINotifications and serviceHandlerImpl
[transportpce.git] / dmaap-client / src / main / java / org / opendaylight / transportpce / dmaap / client / resource / config / ServiceZEndSerializer.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.dmaap.client.resource.config;
9
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.yang.gen.v1.nbi.notifications.rev210813.notification.process.service.ServiceZEnd;
15
16 // This class is a temporary workaround while waiting jackson
17 // support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
18 public class ServiceZEndSerializer extends StdSerializer<ServiceZEnd> {
19     private static final long serialVersionUID = 1L;
20
21     public ServiceZEndSerializer() {
22         super(ServiceZEnd.class);
23     }
24
25     @Override
26     public void serialize(ServiceZEnd value, JsonGenerator gen, SerializerProvider provider) throws IOException {
27         if (value != null) {
28             gen.writeStartObject();
29             gen.writeStringField("clli", value.getClli());
30             if (value.getServiceFormat() != null) {
31                 gen.writeStringField("service-format", value.getServiceFormat().getName());
32             }
33             if (value.getNodeId() != null) {
34                 gen.writeStringField("node-id", value.getNodeId().getValue());
35             }
36             if (value.getServiceRate() != null) {
37                 gen.writeNumberField("service-rate", value.getServiceRate().intValue());
38             }
39             if (value.getOpticType() != null) {
40                 gen.writeStringField("optic-type", value.getOpticType().getName());
41             }
42             if (value.getTxDirection() != null) {
43                 gen.writeObjectField("tx-direction", value.getTxDirection());
44             }
45             if (value.getRxDirection() != null) {
46                 gen.writeObjectField("rx-direction", value.getRxDirection());
47             }
48             gen.writeEndObject();
49         }
50     }
51 }