blob: bf7adac70e29441fbd46afd169a58a37e06ee6f3 [file] [log] [blame]
Jian Liee65a232017-03-29 14:15:30 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Liee65a232017-03-29 14:15:30 +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 Liee65a232017-03-29 14:15:30 +090017
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.mapping.actions.MappingAction;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25/**
26 * Mapping action codec.
27 */
28public final class MappingActionCodec extends JsonCodec<MappingAction> {
29
30 protected static final Logger log =
31 LoggerFactory.getLogger(MappingActionCodec.class);
32
33 protected static final String TYPE = "type";
34 protected static final String ERROR_MESSAGE =
35 " not specified in MappingAction";
36
37 @Override
38 public ObjectNode encode(MappingAction action, CodecContext context) {
39 EncodeMappingActionCodecHelper encoder =
40 new EncodeMappingActionCodecHelper(action, context);
41 return encoder.encode();
42 }
43
44 @Override
45 public MappingAction decode(ObjectNode json, CodecContext context) {
Jian Lif92a2ea2017-04-05 16:06:06 +090046 if (json == null || !json.isObject()) {
47 return null;
48 }
49
Jian Liee65a232017-03-29 14:15:30 +090050 DecodeMappingActionCodecHelper decoder =
51 new DecodeMappingActionCodecHelper(json);
52 return decoder.decode();
53 }
54}