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 com.fasterxml.jackson.core.JsonGenerator;
12 import com.fasterxml.jackson.databind.JsonSerializer;
13 import com.fasterxml.jackson.databind.SerializerProvider;
14 import java.io.IOException;
16 import java.util.Map.Entry;
17 import org.opendaylight.ovsdb.lib.notation.OvsdbMap;
19 public class OvsdbMapSerializer extends JsonSerializer<OvsdbMap<?,?>> {
21 public void serialize(OvsdbMap<?,?> map, JsonGenerator generator,
22 SerializerProvider provider) throws IOException {
23 generator.writeStartArray();
24 generator.writeString("map");
25 generator.writeStartArray();
26 Map<?,?> javaMap = map.delegate();
27 for (Entry<?, ?> entry : javaMap.entrySet()) {
28 Object set = entry.getKey();
29 generator.writeStartArray();
30 generator.writeObject(set);
31 generator.writeObject(entry.getValue());
32 generator.writeEndArray();
34 generator.writeEndArray();
35 generator.writeEndArray();