blob: 39162824ba6b0d840e53f739bab9a58abc9d652e [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;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080020import java.sql.Timestamp;
21
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022import org.codehaus.jackson.JsonGenerator;
23import org.codehaus.jackson.JsonProcessingException;
24import org.codehaus.jackson.map.JsonSerializer;
25import org.codehaus.jackson.map.SerializerProvider;
26
27
28/**
29 * @author subrata
30 *
31 */
32
33public class EventHistoryBaseInfoJSONSerializer extends
34 JsonSerializer<EventHistoryBaseInfo> {
35
36
37 /**
38 * Performs the serialization of a EventHistory.BaseInfo object
39 */
40 @Override
41 public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen,
42 SerializerProvider serializer)
43 throws IOException, JsonProcessingException {
44 jGen.writeStartObject();
45 jGen.writeNumberField("Idx", base_info.getIdx());
46 Timestamp ts = new Timestamp(base_info.getTime_ms());
47 String tsStr = ts.toString();
48 while (tsStr.length() < 23) {
49 tsStr = tsStr.concat("0");
50 }
51 jGen.writeStringField("Time", tsStr);
52 jGen.writeStringField("State", base_info.getState().name());
53 String acStr = base_info.getAction().name().toLowerCase();
54 // Capitalize the first letter
55 acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1));
56 jGen.writeStringField("Action", acStr);
57 jGen.writeEndObject();
58 }
59
60 /**
61 * Tells SimpleModule that we are the serializer for OFMatch
62 */
63 @Override
64 public Class<EventHistoryBaseInfo> handledType() {
65 return EventHistoryBaseInfo.class;
66 }
67}