blob: 9019d664e35620207bc1e6af6a2f9ffa10882930 [file] [log] [blame]
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.codec.impl;
17
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
20import org.onosproject.net.FilteredConnectPoint;
21import org.onosproject.net.behaviour.protection.TransportEndpointDescription;
22import org.onosproject.net.behaviour.protection.TransportEndpointDescription.Builder;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
26/**
27 * JSON Codec for {@link TransportEndpointDescription}.
28 */
29public class TransportEndpointDescriptionCodec
30 extends JsonCodec<TransportEndpointDescription> {
31
32 private static final String OUTPUT = "output";
33 private static final String ENABLED = "enabled";
34
35 @Override
36 public TransportEndpointDescription decode(ObjectNode json,
37 CodecContext context) {
38
39 Builder builder = TransportEndpointDescription.builder();
40 builder.withEnabled(json.get(ENABLED).asBoolean(true));
41 builder.withOutput(context.decode(json.get(OUTPUT), FilteredConnectPoint.class));
42
43 return builder.build();
44 }
45
46 @Override
47 public ObjectNode encode(TransportEndpointDescription entity,
48 CodecContext context) {
49 ObjectNode node = context.mapper().createObjectNode();
50 node.put(ENABLED, entity.isEnabled());
51 node.set(OUTPUT, context.encode(entity.output(), FilteredConnectPoint.class));
52 return node;
53 }
54}