blob: ad57312f11a7bea45050d1dcf1ea65a6d7479521 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package org.openflow.protocol.serializers;
19
20import java.io.IOException;
21
22import org.codehaus.jackson.JsonGenerator;
23import org.codehaus.jackson.JsonProcessingException;
24import org.codehaus.jackson.map.JsonSerializer;
25import org.codehaus.jackson.map.SerializerProvider;
26import org.openflow.protocol.OFFeaturesReply;
27import org.openflow.util.HexString;
28
29public class OFFeaturesReplyJSONSerializer extends JsonSerializer<OFFeaturesReply> {
30
31 /**
32 * Performs the serialization of a OFFeaturesReply object
33 */
34 @Override
35 public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
36 jGen.writeStartObject();
37 jGen.writeNumberField("actions", reply.getActions());
38 jGen.writeNumberField("buffers", reply.getBuffers());
39 jGen.writeNumberField("capabilities", reply.getCapabilities());
40 jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
41 jGen.writeNumberField("length", reply.getLength());
42 serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
43 jGen.writeNumberField("tables", reply.getTables());
44 jGen.writeStringField("type", reply.getType().toString());
45 jGen.writeNumberField("version", reply.getVersion());
46 jGen.writeNumberField("xid", reply.getXid());
47 jGen.writeEndObject();
48 }
49
50 /**
51 * Tells SimpleModule that we are the serializer for OFFeaturesReply
52 */
53 @Override
54 public Class<OFFeaturesReply> handledType() {
55 return OFFeaturesReply.class;
56 }
57}