2 * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.lib.notation.json;
11 import java.io.IOException;
13 import org.opendaylight.ovsdb.lib.notation.OvsdbMap;
15 import com.fasterxml.jackson.core.JsonGenerator;
16 import com.fasterxml.jackson.core.JsonProcessingException;
17 import com.fasterxml.jackson.databind.JsonSerializer;
18 import com.fasterxml.jackson.databind.SerializerProvider;
20 public class OvsdbMapSerializer extends JsonSerializer<OvsdbMap<?,?>> {
22 public void serialize(OvsdbMap<?,?> map, JsonGenerator generator,
23 SerializerProvider provider) throws IOException,
24 JsonProcessingException {
25 generator.writeStartArray();
26 generator.writeString("map");
27 generator.writeStartArray();
28 Map<?,?> javaMap = map.delegate();
29 for (Object set : javaMap.keySet()) {
30 generator.writeStartArray();
31 generator.writeObject(set);
32 generator.writeObject(javaMap.get(set));
33 generator.writeEndArray();
35 generator.writeEndArray();
36 generator.writeEndArray();