Use JsonBodyWriter directly rather than converting JSON to strings first
Change-Id: I2facf51d0bf9b6ea4ccb47b0ac4214af203982a1
Showing
6 changed files
with
19 additions
and
17 deletions
... | @@ -65,7 +65,7 @@ public class FlowsWebResource extends AbstractWebResource { | ... | @@ -65,7 +65,7 @@ public class FlowsWebResource extends AbstractWebResource { |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | - return ok(root.toString()).build(); | 68 | + return ok(root).build(); |
69 | } | 69 | } |
70 | 70 | ||
71 | /** | 71 | /** |
... | @@ -87,7 +87,7 @@ public class FlowsWebResource extends AbstractWebResource { | ... | @@ -87,7 +87,7 @@ public class FlowsWebResource extends AbstractWebResource { |
87 | for (final FlowEntry entry : deviceEntries) { | 87 | for (final FlowEntry entry : deviceEntries) { |
88 | flowsNode.add(flowEntryCodec.encode(entry, this)); | 88 | flowsNode.add(flowEntryCodec.encode(entry, this)); |
89 | } | 89 | } |
90 | - return ok(root.toString()).build(); | 90 | + return ok(root).build(); |
91 | } | 91 | } |
92 | 92 | ||
93 | /** | 93 | /** |
... | @@ -113,6 +113,6 @@ public class FlowsWebResource extends AbstractWebResource { | ... | @@ -113,6 +113,6 @@ public class FlowsWebResource extends AbstractWebResource { |
113 | flowsNode.add(flowEntryCodec.encode(entry, this)); | 113 | flowsNode.add(flowEntryCodec.encode(entry, this)); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | - return ok(root.toString()).build(); | 116 | + return ok(root).build(); |
117 | } | 117 | } |
118 | } | 118 | } | ... | ... |
... | @@ -39,7 +39,7 @@ public class GreetResource extends BaseResource { | ... | @@ -39,7 +39,7 @@ public class GreetResource extends BaseResource { |
39 | ObjectMapper mapper = new ObjectMapper(); | 39 | ObjectMapper mapper = new ObjectMapper(); |
40 | ObjectNode root = mapper.createObjectNode(); | 40 | ObjectNode root = mapper.createObjectNode(); |
41 | root.put("greeting", "Yo!!!!"); | 41 | root.put("greeting", "Yo!!!!"); |
42 | - return Response.ok(root.toString()).build(); | 42 | + return Response.ok(root).build(); |
43 | } | 43 | } |
44 | 44 | ||
45 | } | 45 | } | ... | ... |
... | @@ -42,7 +42,7 @@ public class HostsWebResource extends AbstractWebResource { | ... | @@ -42,7 +42,7 @@ public class HostsWebResource extends AbstractWebResource { |
42 | public Response getHosts() { | 42 | public Response getHosts() { |
43 | final Iterable<Host> hosts = get(HostService.class).getHosts(); | 43 | final Iterable<Host> hosts = get(HostService.class).getHosts(); |
44 | final ObjectNode root = encodeArray(Host.class, "hosts", hosts); | 44 | final ObjectNode root = encodeArray(Host.class, "hosts", hosts); |
45 | - return ok(root.toString()).build(); | 45 | + return ok(root).build(); |
46 | } | 46 | } |
47 | 47 | ||
48 | @GET | 48 | @GET |
... | @@ -52,7 +52,7 @@ public class HostsWebResource extends AbstractWebResource { | ... | @@ -52,7 +52,7 @@ public class HostsWebResource extends AbstractWebResource { |
52 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(id)), | 52 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(id)), |
53 | HOST_NOT_FOUND); | 53 | HOST_NOT_FOUND); |
54 | final ObjectNode root = codec(Host.class).encode(host, this); | 54 | final ObjectNode root = codec(Host.class).encode(host, this); |
55 | - return ok(root.toString()).build(); | 55 | + return ok(root).build(); |
56 | } | 56 | } |
57 | 57 | ||
58 | @GET | 58 | @GET |
... | @@ -63,7 +63,7 @@ public class HostsWebResource extends AbstractWebResource { | ... | @@ -63,7 +63,7 @@ public class HostsWebResource extends AbstractWebResource { |
63 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(mac + "/" + vlan)), | 63 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(mac + "/" + vlan)), |
64 | HOST_NOT_FOUND); | 64 | HOST_NOT_FOUND); |
65 | final ObjectNode root = codec(Host.class).encode(host, this); | 65 | final ObjectNode root = codec(Host.class).encode(host, this); |
66 | - return ok(root.toString()).build(); | 66 | + return ok(root).build(); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ... | ... |
... | @@ -48,7 +48,7 @@ public class IntentsWebResource extends AbstractWebResource { | ... | @@ -48,7 +48,7 @@ public class IntentsWebResource extends AbstractWebResource { |
48 | public Response getIntents() { | 48 | public Response getIntents() { |
49 | final Iterable<Intent> intents = get(IntentService.class).getIntents(); | 49 | final Iterable<Intent> intents = get(IntentService.class).getIntents(); |
50 | final ObjectNode root = encodeArray(Intent.class, "intents", intents); | 50 | final ObjectNode root = encodeArray(Intent.class, "intents", intents); |
51 | - return ok(root.toString()).build(); | 51 | + return ok(root).build(); |
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
... | @@ -72,6 +72,6 @@ public class IntentsWebResource extends AbstractWebResource { | ... | @@ -72,6 +72,6 @@ public class IntentsWebResource extends AbstractWebResource { |
72 | } else { | 72 | } else { |
73 | root = codec(Intent.class).encode(intent, this); | 73 | root = codec(Intent.class).encode(intent, this); |
74 | } | 74 | } |
75 | - return ok(root.toString()).build(); | 75 | + return ok(root).build(); |
76 | } | 76 | } |
77 | } | 77 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import javax.ws.rs.Produces; | ... | @@ -22,6 +22,8 @@ import javax.ws.rs.Produces; |
22 | import javax.ws.rs.core.MediaType; | 22 | import javax.ws.rs.core.MediaType; |
23 | import javax.ws.rs.core.MultivaluedMap; | 23 | import javax.ws.rs.core.MultivaluedMap; |
24 | import javax.ws.rs.ext.MessageBodyWriter; | 24 | import javax.ws.rs.ext.MessageBodyWriter; |
25 | +import javax.ws.rs.ext.Provider; | ||
26 | + | ||
25 | import java.io.IOException; | 27 | import java.io.IOException; |
26 | import java.io.OutputStream; | 28 | import java.io.OutputStream; |
27 | import java.lang.annotation.Annotation; | 29 | import java.lang.annotation.Annotation; |
... | @@ -30,6 +32,7 @@ import java.lang.reflect.Type; | ... | @@ -30,6 +32,7 @@ import java.lang.reflect.Type; |
30 | /** | 32 | /** |
31 | * JAX-RS Response message body writer. | 33 | * JAX-RS Response message body writer. |
32 | */ | 34 | */ |
35 | +@Provider | ||
33 | @Produces("application/json") | 36 | @Produces("application/json") |
34 | public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> { | 37 | public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> { |
35 | 38 | ... | ... |
... | @@ -57,7 +57,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -57,7 +57,7 @@ public class TopologyWebResource extends AbstractWebResource { |
57 | Topology topology = get(TopologyService.class).currentTopology(); | 57 | Topology topology = get(TopologyService.class).currentTopology(); |
58 | ObjectNode root = | 58 | ObjectNode root = |
59 | codec(Topology.class).encode(topology, this); | 59 | codec(Topology.class).encode(topology, this); |
60 | - return ok(root.toString()).build(); | 60 | + return ok(root).build(); |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
... | @@ -74,7 +74,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -74,7 +74,7 @@ public class TopologyWebResource extends AbstractWebResource { |
74 | get(TopologyService.class).getClusters(topology); | 74 | get(TopologyService.class).getClusters(topology); |
75 | ObjectNode root = | 75 | ObjectNode root = |
76 | encodeArray(TopologyCluster.class, "clusters", clusters); | 76 | encodeArray(TopologyCluster.class, "clusters", clusters); |
77 | - return ok(root.toString()).build(); | 77 | + return ok(root).build(); |
78 | } | 78 | } |
79 | 79 | ||
80 | /** | 80 | /** |
... | @@ -96,7 +96,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -96,7 +96,7 @@ public class TopologyWebResource extends AbstractWebResource { |
96 | CLUSTER_NOT_FOUND); | 96 | CLUSTER_NOT_FOUND); |
97 | ObjectNode root = | 97 | ObjectNode root = |
98 | codec(TopologyCluster.class).encode(cluster, this); | 98 | codec(TopologyCluster.class).encode(cluster, this); |
99 | - return ok(root.toString()).build(); | 99 | + return ok(root).build(); |
100 | } | 100 | } |
101 | 101 | ||
102 | /** | 102 | /** |
... | @@ -127,7 +127,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -127,7 +127,7 @@ public class TopologyWebResource extends AbstractWebResource { |
127 | for (DeviceId deviceId : deviceIds) { | 127 | for (DeviceId deviceId : deviceIds) { |
128 | devicesNode.add(deviceId.toString()); | 128 | devicesNode.add(deviceId.toString()); |
129 | } | 129 | } |
130 | - return ok(root.toString()).build(); | 130 | + return ok(root).build(); |
131 | } | 131 | } |
132 | 132 | ||
133 | /** | 133 | /** |
... | @@ -150,7 +150,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -150,7 +150,7 @@ public class TopologyWebResource extends AbstractWebResource { |
150 | Lists.newArrayList(get(TopologyService.class) | 150 | Lists.newArrayList(get(TopologyService.class) |
151 | .getClusterLinks(topology, cluster)); | 151 | .getClusterLinks(topology, cluster)); |
152 | 152 | ||
153 | - return ok(encodeArray(Link.class, "links", links).toString()).build(); | 153 | + return ok(encodeArray(Link.class, "links", links)).build(); |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
... | @@ -203,8 +203,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -203,8 +203,7 @@ public class TopologyWebResource extends AbstractWebResource { |
203 | 203 | ||
204 | return ok(mapper() | 204 | return ok(mapper() |
205 | .createObjectNode() | 205 | .createObjectNode() |
206 | - .put("broadcast", isBroadcast) | 206 | + .put("broadcast", isBroadcast)) |
207 | - .toString()) | ||
208 | .build(); | 207 | .build(); |
209 | } | 208 | } |
210 | 209 | ||
... | @@ -230,7 +229,7 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -230,7 +229,7 @@ public class TopologyWebResource extends AbstractWebResource { |
230 | 229 | ||
231 | return ok(mapper() | 230 | return ok(mapper() |
232 | .createObjectNode() | 231 | .createObjectNode() |
233 | - .put("infrastructure", isInfrastructure).toString()) | 232 | + .put("infrastructure", isInfrastructure)) |
234 | .build(); | 233 | .build(); |
235 | } | 234 | } |
236 | 235 | ... | ... |
-
Please register or login to post a comment