Code ReOrganization and Re-Architecture changes
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / notation / json / OvsDBSetSerializer.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Madhu Venugopal, Ashwin Raveendran
9  */
10 package org.opendaylight.ovsdb.lib.notation.json;
11
12 import java.io.IOException;
13 import java.util.Set;
14
15 import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
16
17 import com.fasterxml.jackson.core.JsonGenerator;
18 import com.fasterxml.jackson.core.JsonProcessingException;
19 import com.fasterxml.jackson.databind.JsonSerializer;
20 import com.fasterxml.jackson.databind.SerializerProvider;
21
22 public class OvsDBSetSerializer extends JsonSerializer<OvsDBSet<?>> {
23     @Override
24     public void serialize(OvsDBSet<?> set, JsonGenerator generator,
25         SerializerProvider provider) throws IOException,
26             JsonProcessingException {
27         generator.writeStartArray();
28         generator.writeString("set");
29         generator.writeStartArray();
30         Set<?> javaSet = set.delegate();
31         for (Object t : javaSet) {
32             generator.writeObject(t);
33         }
34         generator.writeEndArray();
35         generator.writeEndArray();
36     }
37 }