blob: 8d40a4225883379d1b078c34154e479fef0f318a [file] [log] [blame]
jiangrui330b0c92015-11-28 14:09:50 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
jiangrui330b0c92015-11-28 14:09:50 +08003 *
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.vtnweb.web;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.vtnrsc.RouterGateway;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
26/**
27 * Subnet Router Gateway Info codec.
28 */
29public class RouterGatewayInfoCodec extends JsonCodec<RouterGateway> {
30 @Override
31 public ObjectNode encode(RouterGateway routerGateway, CodecContext context) {
32 checkNotNull(routerGateway, "routerGateway cannot be null");
33 ObjectNode result = context.mapper().createObjectNode()
34 .put("network_id", routerGateway.networkId().toString());
35 result.set("external_fixed_ips", new FixedIpCodec()
36 .encode(routerGateway.externalFixedIps(), context));
37 return result;
38 }
39}