Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [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 | */ |
Jian Li | 2e818b0 | 2017-04-12 19:28:30 +0900 | [diff] [blame] | 16 | package org.onosproject.mapping.codec; |
Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [diff] [blame] | 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.JsonCodec; |
| 21 | import org.onosproject.mapping.actions.MappingAction; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | /** |
| 26 | * Mapping action codec. |
| 27 | */ |
| 28 | public final class MappingActionCodec extends JsonCodec<MappingAction> { |
| 29 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 30 | private static final Logger log = |
Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [diff] [blame] | 31 | LoggerFactory.getLogger(MappingActionCodec.class); |
| 32 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 33 | static final String TYPE = "type"; |
| 34 | static final String ERROR_MESSAGE = |
Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [diff] [blame] | 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 Li | f92a2ea | 2017-04-05 16:06:06 +0900 | [diff] [blame] | 46 | if (json == null || !json.isObject()) { |
| 47 | return null; |
| 48 | } |
| 49 | |
Jian Li | ee65a23 | 2017-03-29 14:15:30 +0900 | [diff] [blame] | 50 | DecodeMappingActionCodecHelper decoder = |
| 51 | new DecodeMappingActionCodecHelper(json); |
| 52 | return decoder.decode(); |
| 53 | } |
| 54 | } |