Ray Milkey

Use JsonBodyWriter directly rather than converting JSON to strings first

Change-Id: I2facf51d0bf9b6ea4ccb47b0ac4214af203982a1
......@@ -65,7 +65,7 @@ public class FlowsWebResource extends AbstractWebResource {
}
}
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -87,7 +87,7 @@ public class FlowsWebResource extends AbstractWebResource {
for (final FlowEntry entry : deviceEntries) {
flowsNode.add(flowEntryCodec.encode(entry, this));
}
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -113,6 +113,6 @@ public class FlowsWebResource extends AbstractWebResource {
flowsNode.add(flowEntryCodec.encode(entry, this));
}
}
return ok(root.toString()).build();
return ok(root).build();
}
}
......
......@@ -39,7 +39,7 @@ public class GreetResource extends BaseResource {
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = mapper.createObjectNode();
root.put("greeting", "Yo!!!!");
return Response.ok(root.toString()).build();
return Response.ok(root).build();
}
}
......
......@@ -42,7 +42,7 @@ public class HostsWebResource extends AbstractWebResource {
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 @@ public class HostsWebResource extends AbstractWebResource {
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 @@ public class HostsWebResource extends AbstractWebResource {
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();
}
}
......
......@@ -48,7 +48,7 @@ public class IntentsWebResource extends AbstractWebResource {
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 @@ public class IntentsWebResource extends AbstractWebResource {
} else {
root = codec(Intent.class).encode(intent, this);
}
return ok(root.toString()).build();
return ok(root).build();
}
}
......
......@@ -22,6 +22,8 @@ import javax.ws.rs.Produces;
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 @@ import java.lang.reflect.Type;
/**
* JAX-RS Response message body writer.
*/
@Provider
@Produces("application/json")
public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> {
......
......@@ -57,7 +57,7 @@ public class TopologyWebResource extends AbstractWebResource {
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 @@ public class TopologyWebResource extends AbstractWebResource {
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 @@ public class TopologyWebResource extends AbstractWebResource {
CLUSTER_NOT_FOUND);
ObjectNode root =
codec(TopologyCluster.class).encode(cluster, this);
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -127,7 +127,7 @@ public class TopologyWebResource extends AbstractWebResource {
for (DeviceId deviceId : deviceIds) {
devicesNode.add(deviceId.toString());
}
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -150,7 +150,7 @@ public class TopologyWebResource extends AbstractWebResource {
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 @@ public class TopologyWebResource extends AbstractWebResource {
return ok(mapper()
.createObjectNode()
.put("broadcast", isBroadcast)
.toString())
.put("broadcast", isBroadcast))
.build();
}
......@@ -230,7 +229,7 @@ public class TopologyWebResource extends AbstractWebResource {
return ok(mapper()
.createObjectNode()
.put("infrastructure", isInfrastructure).toString())
.put("infrastructure", isInfrastructure))
.build();
}
......