List of usage examples for com.google.gson JsonNull JsonNull
@Deprecated
public JsonNull()
From source file:com.crypticbit.diff.demo.swing.contacts.JsonEditPanel.java
License:Apache License
/** * Default constructor for the JSONEditPanel object. Creates an empty tree. *///www. j av a 2 s .c o m public JsonEditPanel() { setLayout(new BorderLayout()); JsonJTreeNode root = new JsonJTreeNode(null, -1, new JsonNull()); jTree = new JTree(root); jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); add(new JScrollPane(jTree), BorderLayout.CENTER); }
From source file:com.crypticbit.diff.demo.swing.contacts.JsonEditPanel.java
License:Apache License
/** * Deletes selected node or sets entire model to null if root node or no node is selected. *//*from www. j a va2 s.c o m*/ public void deleteNode() { TreePath selection = jTree.getSelectionPath(); if (selection == null) { // Replace root with emptyness jTree.setModel(new DefaultTreeModel(new JsonJTreeNode(null, -1, new JsonNull()))); } else { JsonJTreeNode node = (JsonJTreeNode) selection.getLastPathComponent(); JsonJTreeNode parent = (JsonJTreeNode) node.getParent(); if (parent == null) { // Replace root with emptyness jTree.setModel(new DefaultTreeModel(new JsonJTreeNode(null, -1, new JsonNull()))); } else { node.removeFromParent(); ((DefaultTreeModel) jTree.getModel()).reload(parent); } } }
From source file:com.crypticbit.diff.demo.swing.JSONEditPanel.java
License:Apache License
/** * Default constructor for the JSONEditPanel object. Creates an empty tree. *//* w ww . jav a2 s .c o m*/ public JSONEditPanel() { setLayout(new BorderLayout()); JSONJTreeNode root = new JSONJTreeNode(null, -1, new JsonNull()); jTree = new JTree(root); jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); add(new JScrollPane(jTree), BorderLayout.CENTER); }
From source file:com.crypticbit.diff.demo.swing.JSONEditPanel.java
License:Apache License
/** * Deletes selected node or sets entire model to null if root node or no node is selected. *///w w w.j a v a 2 s . com public void deleteNode() { TreePath selection = jTree.getSelectionPath(); if (selection == null) { // Replace root with emptyness jTree.setModel(new DefaultTreeModel(new JSONJTreeNode(null, -1, new JsonNull()))); } else { JSONJTreeNode node = (JSONJTreeNode) selection.getLastPathComponent(); JSONJTreeNode parent = (JSONJTreeNode) node.getParent(); if (parent == null) { // Replace root with emptyness jTree.setModel(new DefaultTreeModel(new JSONJTreeNode(null, -1, new JsonNull()))); } else { node.removeFromParent(); ((DefaultTreeModel) jTree.getModel()).reload(parent); } } }
From source file:com.github.autermann.matlab.json.MatlabValueSerializer.java
License:Open Source License
@Override public JsonElement serialize(MatlabValue value, Type type, JsonSerializationContext ctx) { if (value == null) { return new JsonNull(); }/*ww w . ja va 2 s. c om*/ JsonObject object = new JsonObject(); object.addProperty(MatlabJSONConstants.TYPE, value.getType().toString()); object.add(MatlabJSONConstants.VALUE, value.accept(new VisitingSerializer(ctx))); return object; }
From source file:com.google.gwtjsonrpc.server.JsonServlet.java
License:Apache License
private String formatResult(final ActiveCall call) throws UnsupportedEncodingException, IOException { final GsonBuilder gb = createGsonBuilder(); gb.registerTypeAdapter(call.getClass(), new JsonSerializer<ActiveCall>() { public JsonElement serialize(final ActiveCall src, final Type typeOfSrc, final JsonSerializationContext context) { if (call.callback != null) { if (src.externalFailure != null) { return new JsonNull(); }/*from w w w .ja v a 2s. c om*/ return context.serialize(src.result); } final JsonObject r = new JsonObject(); r.add(src.versionName, src.versionValue); if (src.id != null) { r.add("id", src.id); } if (src.xsrfKeyOut != null) { r.addProperty("xsrfKey", src.xsrfKeyOut); } if (src.externalFailure != null) { final JsonObject error = new JsonObject(); if ("jsonrpc".equals(src.versionName)) { final int code = to2_0ErrorCode(src); error.addProperty("code", code); error.addProperty("message", src.externalFailure.getMessage()); } else { error.addProperty("name", "JSONRPCError"); error.addProperty("code", 999); error.addProperty("message", src.externalFailure.getMessage()); } r.add("error", error); } else { r.add("result", context.serialize(src.result)); } return r; } }); final StringWriter o = new StringWriter(); if (call.callback != null) { o.write(call.callback); o.write("("); } gb.create().toJson(call, o); if (call.callback != null) { o.write(");"); } o.close(); return o.toString(); }
From source file:com.google.gwtjsonrpc.server.MapDeserializer.java
License:Apache License
public JsonElement serialize(final Map<Object, Object> src, final Type typeOfSrc, final JsonSerializationContext context) { final Type kt = ((ParameterizedType) typeOfSrc).getActualTypeArguments()[0]; final Type vt = ((ParameterizedType) typeOfSrc).getActualTypeArguments()[1]; if (src == null) { return new JsonNull(); }/*from w w w.ja v a 2 s. com*/ if (kt == String.class) { final JsonObject r = new JsonObject(); for (final Map.Entry<Object, Object> e : src.entrySet()) { r.add(e.getKey().toString(), context.serialize(e.getValue(), vt)); } return r; } else { final JsonArray r = new JsonArray(); for (final Map.Entry<Object, Object> e : src.entrySet()) { r.add(context.serialize(e.getKey(), kt)); r.add(context.serialize(e.getValue(), vt)); } return r; } }
From source file:com.google.gwtjsonrpc.server.SqlDateDeserializer.java
License:Apache License
public JsonElement serialize(final java.sql.Date src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonNull(); }/*from w w w. ja va2 s. c o m*/ return new JsonPrimitive(src.toString()); }
From source file:com.google.gwtjsonrpc.server.SqlTimestampDeserializer.java
License:Apache License
public JsonElement serialize(final java.sql.Timestamp src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonNull(); }/*from ww w. j a v a2s .c om*/ return new JsonPrimitive(newFormat().format(src) + "000000"); }
From source file:org.apache.tika.io.json.JsonMetadataSerializer.java
License:Apache License
/** * /*from w ww . j av a 2s. c om*/ * @param metadata * @param type * @param context * @return JsonObject with key/value(s) pairs or JsonNull if metadata is null. */ @Override public JsonElement serialize(Metadata metadata, Type type, JsonSerializationContext context) { if (metadata == null) { return new JsonNull(); } String[] names = getNames(metadata); if (names == null) { return new JsonNull(); } JsonObject root = new JsonObject(); for (String n : names) { String[] vals = metadata.getValues(n); if (vals == null) { //silently skip? continue; } if (vals.length == 1) { root.addProperty(n, vals[0]); } else { JsonArray jArr = new JsonArray(); for (int i = 0; i < vals.length; i++) { jArr.add(new JsonPrimitive(vals[i])); } root.add(n, jArr); } } return root; }