blob: 2d6f32151b4bd7e0d3b8b2b221e27894804f1fe5 [file] [log] [blame]
Wailok Shumee90c132021-03-11 21:00:11 +08001/*
2 * Copyright 2021-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 */
pierventreb37a11a2021-03-18 16:50:04 +010016package org.onosproject.segmentrouting.policy.impl;
Wailok Shumee90c132021-03-11 21:00:11 +080017
18import com.fasterxml.jackson.databind.node.ObjectNode;
19
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
pierventreb37a11a2021-03-18 16:50:04 +010022import org.onosproject.segmentrouting.policy.api.DropPolicy;
Wailok Shumee90c132021-03-11 21:00:11 +080023
24/**
25 * Codec of DropPolicy class.
26 */
27public final class DropPolicyCodec extends JsonCodec<DropPolicy> {
28
29 // JSON field names
30 public static final String POLICY_ID = "policy_id";
31 public static final String POLICY_TYPE = "policy_type";
32
33 @Override
34 public ObjectNode encode(DropPolicy policy, CodecContext context) {
35 final ObjectNode result = context.mapper().createObjectNode()
36 .put(POLICY_ID, policy.policyId().toString())
37 .put(POLICY_TYPE, policy.policyType().toString());
38
39 return result;
40 }
41
42 @Override
43 public DropPolicy decode(ObjectNode json, CodecContext context) {
44 return new DropPolicy();
45 }
46}