Backward compatibilty support for Northbound v2 GET operation. 85/8885/1
authorMadhu Venugopal <mavenugo@gmail.com>
Thu, 10 Jul 2014 02:26:44 +0000 (19:26 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Thu, 10 Jul 2014 02:26:44 +0000 (19:26 -0700)
Sample output for a GET operation based on latest topic/schema branch : https://gist.github.com/1fc3dd2eb4d2391d16df
This provides the backward compatible support as in Hydrogen release.

Northbound v3 support will bring in the new and improved version of GET/PUT/POST operation.

Change-Id: I082afe8ef87ad594f0467d96f103dbed45888d5f
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
library/src/main/java/org/opendaylight/ovsdb/lib/notation/Row.java
library/src/main/java/org/opendaylight/ovsdb/lib/notation/json/RowSerializer.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/schema/ColumnType.java

index da52816ea43d8305d476af1d0dc1f5bc29bae59b..c1e1b16c3d56b42ed5721e9b575cc931d92ef725 100644 (file)
@@ -16,12 +16,15 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import org.opendaylight.ovsdb.lib.notation.json.RowSerializer;
 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.google.common.collect.Maps;
 
+@JsonSerialize(using = RowSerializer.class)
 public class Row<E extends TableSchema<E>> {
     @JsonIgnore
     private TableSchema<E> tableSchema;
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/notation/json/RowSerializer.java b/library/src/main/java/org/opendaylight/ovsdb/lib/notation/json/RowSerializer.java
new file mode 100644 (file)
index 0000000..dc9c504
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.lib.notation.json;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.opendaylight.ovsdb.lib.notation.Column;
+import org.opendaylight.ovsdb.lib.notation.Row;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+public class RowSerializer extends JsonSerializer<Row> {
+    @Override
+    public void serialize(Row row, JsonGenerator generator,
+        SerializerProvider provider) throws IOException,
+            JsonProcessingException {
+        generator.writeStartObject();
+        Collection<Column> columns = row.getColumns();
+        for (Column<?,?> column : columns) {
+            generator.writeObjectField(column.getSchema().getName(), column.getData());
+        }
+        generator.writeEndObject();
+    }
+}
index 58263dab21c8cd1d8c5ff3645ca7d3b746d2ef99..a17414d256be8128faee52b552df605cd3d33b77 100644 (file)
@@ -9,15 +9,13 @@
  */
 package org.opendaylight.ovsdb.lib.schema;
 
-import java.util.Set;
-
 import org.opendaylight.ovsdb.lib.error.TyperException;
 import org.opendaylight.ovsdb.lib.jsonrpc.JsonUtils;
 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
+import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
 import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.Sets;
 
 
 public abstract class ColumnType {
@@ -165,7 +163,7 @@ public abstract class ColumnType {
         @Override
         public Object valueFromJson(JsonNode value) {
             if (isMultiValued()) {
-                Set<Object> result = Sets.newHashSet();
+                OvsDBSet<Object> result = new OvsDBSet<Object>();
                 if(value.isArray()) {
                     if (value.size() == 2) {
                         if (value.get(0).isTextual() && "set".equals(value.get(0).asText())) {