blob: 8a4218d43be4befa074a713d96498d3946ddbd6d [file] [log] [blame]
yjimmyycfcb0532016-07-11 16:03:48 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
yjimmyycfcb0532016-07-11 16:03:48 -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.driver.extensions.codec;
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.driver.extensions.OplinkAttenuation;
23
24import static org.onlab.util.Tools.nullIsIllegal;
25
26/**
27 * JSON Codec for OplinkAttenuation class.
28 */
29public class OplinkAttenuationCodec extends JsonCodec<OplinkAttenuation> {
30 private static final String ATTENUATION = "attenuation";
31 private static final String MISSING_ATT = "Missing value for \"attenuation\"";
32
33 @Override
34 public OplinkAttenuation decode(ObjectNode json, CodecContext context) {
35 if (json == null || !json.isObject()) {
36 return null;
37 }
38 String att = nullIsIllegal(json.get(ATTENUATION), MISSING_ATT).asText();
39 return new OplinkAttenuation(Integer.valueOf(att));
40 }
41}