Updating fix for bug 3989 based on discussion in OVSDB meeting
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / notation / json / OvsdbSetSerializer.java
1 /*
2  * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.lib.notation.json;
10
11 import java.io.IOException;
12 import java.util.Set;
13
14 import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
15
16 import com.fasterxml.jackson.core.JsonGenerator;
17 import com.fasterxml.jackson.core.JsonProcessingException;
18 import com.fasterxml.jackson.databind.JsonSerializer;
19 import com.fasterxml.jackson.databind.SerializerProvider;
20
21 public class OvsdbSetSerializer extends JsonSerializer<OvsdbSet<?>> {
22     @Override
23     public void serialize(OvsdbSet<?> set, JsonGenerator generator,
24         SerializerProvider provider) throws IOException,
25             JsonProcessingException {
26         generator.writeStartArray();
27         generator.writeString("set");
28         generator.writeStartArray();
29         Set<?> javaSet = set.delegate();
30         for (Object setObject : javaSet) {
31             generator.writeObject(setObject);
32         }
33         generator.writeEndArray();
34         generator.writeEndArray();
35     }
36 }