blob: 8c8a5a02df6390b9e359d3336d9a36d8690b37cb [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.soam.web;
17
18import java.util.ArrayList;
19import java.util.List;
20
21import org.onosproject.codec.CodecContext;
22import org.onosproject.codec.JsonCodec;
23import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.MeasurementOption;
24
25import com.fasterxml.jackson.databind.node.ArrayNode;
26
27/**
28 * Encode and decode to/from JSON to MeasurementOption object.
29 */
30public class DmMeasurementOptionCodec extends JsonCodec<MeasurementOption> {
31
32 @Override
33 public ArrayNode encode(Iterable<MeasurementOption> entities,
34 CodecContext context) {
35 ArrayNode an = context.mapper().createArrayNode();
36 entities.forEach(node -> an.add(node.name()));
37
38 return an;
39 }
40
41 @Override
42 public List<MeasurementOption> decode(ArrayNode json,
43 CodecContext context) {
44 if (json == null) {
45 return null;
46 }
47 List<MeasurementOption> moList = new ArrayList<>();
48 json.forEach(node -> moList.add(MeasurementOption.valueOf(node.asText())));
49 return moList;
50 }
51
52}