Refactor NBINotifications and serviceHandlerImpl
[transportpce.git] / dmaap-client / src / main / java / org / opendaylight / transportpce / dmaap / client / resource / config / PublishNotificationProcessServiceSerializer.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.PublishNotificationProcessService;
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 PublishNotificationProcessServiceSerializer extends StdSerializer<PublishNotificationProcessService> {
19     private static final long serialVersionUID = 1L;
20
21     public PublishNotificationProcessServiceSerializer() {
22         super(PublishNotificationProcessService.class);
23     }
24
25     @Override
26     public void serialize(PublishNotificationProcessService value, JsonGenerator gen, SerializerProvider provider)
27             throws IOException {
28         if (value != null) {
29             gen.writeStartObject();
30             gen.writeStringField("common-id", value.getCommonId());
31             gen.writeStringField("message", value.getMessage());
32             gen.writeStringField("response-failed", value.getResponseFailed());
33             gen.writeStringField("service-name", value.getServiceName());
34             gen.writeStringField("publisher-name", value.getPublisherName());
35             if (value.getOperationalState() != null) {
36                 gen.writeStringField("operational-state", value.getOperationalState().getName());
37             }
38             gen.writeObjectField("service-a-end", value.getServiceAEnd());
39             gen.writeObjectField("service-z-end", value.getServiceZEnd());
40             gen.writeEndObject();
41         }
42     }
43
44 }