Browse Source

Compare apples to apples

Json controller now replies with a Message object
instead of a Map. Creating tons of maps is memory
intensive, plus this tests Jackson's ability to
serialize a bean instead of a Map.
Ryan Tenney 12 years ago
parent
commit
295137f19c
1 changed files with 20 additions and 4 deletions
  1. 20 4
      spring/src/main/java/hello/web/HelloJsonController.java

+ 20 - 4
spring/src/main/java/hello/web/HelloJsonController.java

@@ -21,10 +21,26 @@ public class HelloJsonController
 
 
   @RequestMapping(value = "/json", produces = "application/json")
   @RequestMapping(value = "/json", produces = "application/json")
   @ResponseBody
   @ResponseBody
-  public Map<String, String> json()
+  public Message json()
   {
   {
-    Map<String, String> map = new HashMap<String, String>();
-    map.put("message", "Hello, world");
-    return map;
+    return new Message("Hello, world");
   }
   }
+
+  public static class Message
+  {
+
+    private final String message;
+
+    public Message(String message)
+    {
+      this.message = message;
+    }
+
+    public String getMessage()
+    {
+      return message;
+    }
+
+  }
+
 }
 }