Pingping Lin | 339cdfb | 2015-06-04 10:02:47 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Pingping Lin | 339cdfb | 2015-06-04 10:02:47 -0700 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package org.onosproject.virtualbng; |
| 18 | |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | |
| 23 | import java.util.Map.Entry; |
| 24 | |
| 25 | import org.onlab.packet.IpAddress; |
| 26 | import org.onosproject.codec.CodecContext; |
| 27 | import org.onosproject.codec.JsonCodec; |
| 28 | |
| 29 | /** |
| 30 | * Codec for encoding a IP address mapping entry to JSON. |
| 31 | */ |
| 32 | public 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 | } |