yjimmyy | cfcb053 | 2016-07-11 16:03:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
yjimmyy | cfcb053 | 2016-07-11 16:03:48 -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.driver.extensions.codec; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | import org.onosproject.driver.extensions.OplinkAttenuation; |
| 23 | |
| 24 | import static org.onlab.util.Tools.nullIsIllegal; |
| 25 | |
| 26 | /** |
| 27 | * JSON Codec for OplinkAttenuation class. |
| 28 | */ |
| 29 | public 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 | } |