blob: 4f238c9a4756f196bce13ec47e73daf8dc9fc151 [file] [log] [blame]
Pingping Lin339cdfb2015-06-04 10:02:47 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Pingping Lin339cdfb2015-06-04 10:02:47 -07003 *
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 */
16
17package org.onosproject.virtualbng;
18
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import com.fasterxml.jackson.databind.node.ObjectNode;
22
23import java.util.Map.Entry;
24
25import org.onlab.packet.IpAddress;
26import org.onosproject.codec.CodecContext;
27import org.onosproject.codec.JsonCodec;
28
29/**
30 * Codec for encoding a IP address mapping entry to JSON.
31 */
32public final class IpAddressMapEntryCodec extends JsonCodec<Entry<IpAddress, IpAddress>> {
33
34 @Override
35 public ObjectNode encode(Entry<IpAddress, IpAddress> entry, CodecContext context) {
36 checkNotNull(entry, "IP address map entry cannot be null");
37 final ObjectNode result = context.mapper().createObjectNode()
38 .put(entry.getKey().toString(), entry.getValue().toString());
39
40 return result;
41 }
42}