Use JsonBodyWriter directly rather than converting JSON to strings first
Change-Id: I2facf51d0bf9b6ea4ccb47b0ac4214af203982a1
diff --git a/web/api/src/main/java/org/onosproject/rest/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/FlowsWebResource.java
index 24ee73a..36afcce 100644
--- a/web/api/src/main/java/org/onosproject/rest/FlowsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/FlowsWebResource.java
@@ -65,7 +65,7 @@
}
}
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -87,7 +87,7 @@
for (final FlowEntry entry : deviceEntries) {
flowsNode.add(flowEntryCodec.encode(entry, this));
}
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -113,6 +113,6 @@
flowsNode.add(flowEntryCodec.encode(entry, this));
}
}
- return ok(root.toString()).build();
+ return ok(root).build();
}
}
diff --git a/web/api/src/main/java/org/onosproject/rest/GreetResource.java b/web/api/src/main/java/org/onosproject/rest/GreetResource.java
index f3db807..374ce28 100644
--- a/web/api/src/main/java/org/onosproject/rest/GreetResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/GreetResource.java
@@ -39,7 +39,7 @@
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = mapper.createObjectNode();
root.put("greeting", "Yo!!!!");
- return Response.ok(root.toString()).build();
+ return Response.ok(root).build();
}
}
diff --git a/web/api/src/main/java/org/onosproject/rest/HostsWebResource.java b/web/api/src/main/java/org/onosproject/rest/HostsWebResource.java
index 6a0f44a..925df13 100644
--- a/web/api/src/main/java/org/onosproject/rest/HostsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/HostsWebResource.java
@@ -42,7 +42,7 @@
public Response getHosts() {
final Iterable<Host> hosts = get(HostService.class).getHosts();
final ObjectNode root = encodeArray(Host.class, "hosts", hosts);
- return ok(root.toString()).build();
+ return ok(root).build();
}
@GET
@@ -52,7 +52,7 @@
final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(id)),
HOST_NOT_FOUND);
final ObjectNode root = codec(Host.class).encode(host, this);
- return ok(root.toString()).build();
+ return ok(root).build();
}
@GET
@@ -63,7 +63,7 @@
final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(mac + "/" + vlan)),
HOST_NOT_FOUND);
final ObjectNode root = codec(Host.class).encode(host, this);
- return ok(root.toString()).build();
+ return ok(root).build();
}
}
diff --git a/web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java b/web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java
index 4a2639f..75287e0 100644
--- a/web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java
@@ -48,7 +48,7 @@
public Response getIntents() {
final Iterable<Intent> intents = get(IntentService.class).getIntents();
final ObjectNode root = encodeArray(Intent.class, "intents", intents);
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -72,6 +72,6 @@
} else {
root = codec(Intent.class).encode(intent, this);
}
- return ok(root.toString()).build();
+ return ok(root).build();
}
}
diff --git a/web/api/src/main/java/org/onosproject/rest/JsonBodyWriter.java b/web/api/src/main/java/org/onosproject/rest/JsonBodyWriter.java
index 3305f7d..e693544 100644
--- a/web/api/src/main/java/org/onosproject/rest/JsonBodyWriter.java
+++ b/web/api/src/main/java/org/onosproject/rest/JsonBodyWriter.java
@@ -22,6 +22,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
@@ -30,6 +32,7 @@
/**
* JAX-RS Response message body writer.
*/
+@Provider
@Produces("application/json")
public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> {
diff --git a/web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java b/web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java
index 92fc23b..a10232c 100644
--- a/web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java
@@ -57,7 +57,7 @@
Topology topology = get(TopologyService.class).currentTopology();
ObjectNode root =
codec(Topology.class).encode(topology, this);
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -74,7 +74,7 @@
get(TopologyService.class).getClusters(topology);
ObjectNode root =
encodeArray(TopologyCluster.class, "clusters", clusters);
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -96,7 +96,7 @@
CLUSTER_NOT_FOUND);
ObjectNode root =
codec(TopologyCluster.class).encode(cluster, this);
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -127,7 +127,7 @@
for (DeviceId deviceId : deviceIds) {
devicesNode.add(deviceId.toString());
}
- return ok(root.toString()).build();
+ return ok(root).build();
}
/**
@@ -150,7 +150,7 @@
Lists.newArrayList(get(TopologyService.class)
.getClusterLinks(topology, cluster));
- return ok(encodeArray(Link.class, "links", links).toString()).build();
+ return ok(encodeArray(Link.class, "links", links)).build();
}
/**
@@ -203,8 +203,7 @@
return ok(mapper()
.createObjectNode()
- .put("broadcast", isBroadcast)
- .toString())
+ .put("broadcast", isBroadcast))
.build();
}
@@ -230,7 +229,7 @@
return ok(mapper()
.createObjectNode()
- .put("infrastructure", isInfrastructure).toString())
+ .put("infrastructure", isInfrastructure))
.build();
}