blob: 6f1d1ff8bdf677bbe3c59fcdaec9cdac0985f0a2 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3*
4* Licensed under the Apache License, Version 2.0 (the "License"); you may
5* not use this file except in compliance with the License. You may obtain
6* 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, WITHOUT
12* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13* License for the specific language governing permissions and limitations
14* under the License.
15**/
16
17package net.floodlightcontroller.util;
18
19import java.io.IOException;
20
21import java.sql.Timestamp;
22
23
24import org.codehaus.jackson.JsonGenerator;
25import org.codehaus.jackson.JsonProcessingException;
26import org.codehaus.jackson.map.JsonSerializer;
27import org.codehaus.jackson.map.SerializerProvider;
28
29
30/**
31 * @author subrata
32 *
33 */
34
35public class EventHistoryBaseInfoJSONSerializer extends
36 JsonSerializer<EventHistoryBaseInfo> {
37
38
39 /**
40 * Performs the serialization of a EventHistory.BaseInfo object
41 */
42 @Override
43 public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen,
44 SerializerProvider serializer)
45 throws IOException, JsonProcessingException {
46 jGen.writeStartObject();
47 jGen.writeNumberField("Idx", base_info.getIdx());
48 Timestamp ts = new Timestamp(base_info.getTime_ms());
49 String tsStr = ts.toString();
50 while (tsStr.length() < 23) {
51 tsStr = tsStr.concat("0");
52 }
53 jGen.writeStringField("Time", tsStr);
54 jGen.writeStringField("State", base_info.getState().name());
55 String acStr = base_info.getAction().name().toLowerCase();
56 // Capitalize the first letter
57 acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1));
58 jGen.writeStringField("Action", acStr);
59 jGen.writeEndObject();
60 }
61
62 /**
63 * Tells SimpleModule that we are the serializer for OFMatch
64 */
65 @Override
66 public Class<EventHistoryBaseInfo> handledType() {
67 return EventHistoryBaseInfo.class;
68 }
69}