2 * © 2013 xplosion interactive
5 package net.pterodactylus.sone.web.ajax;
9 import com.fasterxml.jackson.annotation.JsonProperty;
10 import com.fasterxml.jackson.annotation.JsonUnwrapped;
11 import com.fasterxml.jackson.databind.JsonNode;
12 import com.fasterxml.jackson.databind.node.BooleanNode;
13 import com.fasterxml.jackson.databind.node.IntNode;
14 import com.fasterxml.jackson.databind.node.TextNode;
15 import com.google.common.collect.Maps;
18 * JSON return object for AJAX requests.
20 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
22 public class JsonReturnObject {
24 /** Whether the request was successful. */
26 private final boolean success;
28 /** The returned values. */
30 private final Map<String, JsonNode> content = Maps.newHashMap();
33 * Creates a new JSON return object.
36 * {@code true} if the request was successful, {@code false} otherwise
38 public JsonReturnObject(boolean success) {
39 this.success = success;
47 * Stores the given value under the given key.
50 * The key under which to store the value
53 * @return This JSON return object
55 public JsonReturnObject put(String key, boolean value) {
56 return put(key, BooleanNode.valueOf(value));
60 * Stores the given value under the given key.
63 * The key under which to store the value
66 * @return This JSON return object
68 public JsonReturnObject put(String key, int value) {
69 return put(key, new IntNode(value));
73 * Stores the given value under the given key.
76 * The key under which to store the value
79 * @return This JSON return object
81 public JsonReturnObject put(String key, String value) {
82 return put(key, new TextNode(value));
86 * Stores the given value under the given key.
89 * The key under which to store the value
92 * @return This JSON return object
94 public JsonReturnObject put(String key, JsonNode value) {
95 content.put(key, value);