blob: 407bd080eb06157c3915bdbaa928578bf5eb27ae [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 */
16package org.onosproject.segmentrouting.policy.api;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22
23/**
24 * Codec of DropPolicy class.
25 */
26public final class DropPolicyCodec extends JsonCodec<DropPolicy> {
27
28 // JSON field names
29 public static final String POLICY_ID = "policy_id";
30 public static final String POLICY_TYPE = "policy_type";
31
32 @Override
33 public ObjectNode encode(DropPolicy policy, CodecContext context) {
34 final ObjectNode result = context.mapper().createObjectNode()
35 .put(POLICY_ID, policy.policyId().toString())
36 .put(POLICY_TYPE, policy.policyType().toString());
37
38 return result;
39 }
40
41 @Override
42 public DropPolicy decode(ObjectNode json, CodecContext context) {
43 return new DropPolicy();
44 }
45}