blob: fe404b42186047e869c10a72d323d526804c20cf [file] [log] [blame]
Jian Li45083522017-03-20 18:46:07 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li45083522017-03-20 18:46:07 +09003 *
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 */
Jian Li2e818b02017-04-12 19:28:30 +090016package org.onosproject.mapping.codec;
Jian Li45083522017-03-20 18:46:07 +090017
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.mapping.addresses.MappingAddress;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25/**
26 * Mapping address codec.
27 */
28public final class MappingAddressCodec extends JsonCodec<MappingAddress> {
29
30 protected static final Logger log =
31 LoggerFactory.getLogger(MappingAddressCodec.class);
32
33 protected static final String TYPE = "type";
34 protected static final String IPV4 = "ipv4";
35 protected static final String IPV6 = "ipv6";
36 protected static final String MAC = "mac";
37 protected static final String DN = "dn";
38 protected static final String AS = "as";
39
40 @Override
41 public ObjectNode encode(MappingAddress address, CodecContext context) {
42 EncodeMappingAddressCodecHelper encoder =
43 new EncodeMappingAddressCodecHelper(address, context);
44 return encoder.encode();
45 }
46
47 @Override
48 public MappingAddress decode(ObjectNode json, CodecContext context) {
Jian Lif92a2ea2017-04-05 16:06:06 +090049 if (json == null || !json.isObject()) {
50 return null;
51 }
52
Jian Li45083522017-03-20 18:46:07 +090053 DecodeMappingAddressCodecHelper decoder =
54 new DecodeMappingAddressCodecHelper(json);
55 return decoder.decode();
56 }
57}