List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeAttributeRequests(JsonObject json, JsonDeserializationContext context) { return new AttributeRequest((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (String[]) context.deserialize(json.get("attributes"), String[].class)); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeAttributeReply(JsonObject json, JsonDeserializationContext context) { return new AttributeReply((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (Attribute[]) context.deserialize(json.get("values"), Attribute[].class)); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeGroupPutReply(JsonObject json, JsonDeserializationContext context) { return new GroupPutReply((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), json.get("tupleSession").getAsInt()); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializePutRequest(JsonObject json, JsonDeserializationContext context) { return new PutRequest((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (Tuple) context.deserialize(json.get("tuple"), Tuple.class)); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeGetRequest(JsonObject json, JsonDeserializationContext context) { return new GetRequest((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (Template) context.deserialize(json.get("template"), Template.class)); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeQueryRequest(JsonObject json, JsonDeserializationContext context) { return new QueryRequest((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (Template) context.deserialize(json.get("template"), Template.class)); }
From source file:org.cmg.jresp.json.MessageDeserializer.java
License:Open Source License
private jRESPMessage doDeserializeTupleReply(JsonObject json, JsonDeserializationContext context) { return new TupleReply((PointToPoint) context.deserialize(json.get("source"), PointToPoint.class), json.get("session").getAsInt(), json.get("target").getAsString(), (Tuple) context.deserialize(json.get("tuple"), Tuple.class)); }
From source file:org.cmg.jresp.json.SCELJsonUtil.java
License:Open Source License
/** * Deserialize an object from a {@link JsonElement}. We assume that the * received JsonElement is a {@link JsonObject} providing two attributes: * <ul>// www. j a va 2s.com * <li><code>type</code>, containing a string with the fully qualified name * of the serialized object; * <li><code>value</code>, containing the {@link JsonElement} associated to * the serialized object. * </ul> * * * @param json * element to deserialize * @param context * context for serialization * @return the object represented by json */ public static Object objectFromJson(JsonElement json, JsonDeserializationContext context) { if (!json.isJsonObject()) { throw new JsonParseException("Unexpected JsonElement!"); } JsonObject jo = (JsonObject) json; if ((!jo.has("type")) || (!jo.has("value"))) { throw new JsonParseException("Required attributes are not available!"); } String className = jo.get(TYPE_ID).getAsString(); try { Class<?> c = Class.forName(className); return context.deserialize(jo.get(VALUE_ID), c); } catch (ClassNotFoundException e) { throw new JsonParseException(e); } }
From source file:org.commonjava.couch.io.json.CouchObjectListDeserializer.java
License:Apache License
@Override public CouchObjectList<T> deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final boolean useDocElement = CouchDocument.class.isAssignableFrom(type); final List<T> items = new ArrayList<T>(); final JsonElement rowsRaw = json.getAsJsonObject().get(ROWS); if (rowsRaw == null) { throw new JsonParseException("Cannot find " + ROWS + " field within root object."); }/* w w w. j a v a 2 s . c o m*/ final JsonArray rows = rowsRaw.getAsJsonArray(); for (final JsonElement row : rows) { final JsonObject rowObj = row.getAsJsonObject(); JsonElement data = rowObj; if (useDocElement) { data = rowObj.get(DOC_ELEMENT); if (data == null) { if (allowMissing) { continue; } throw new JsonParseException("Cannot find " + DOC_ELEMENT + " field within row: " + row + "\nDid you access the view with the '?include_docs=true' query parameter?"); } } final Object val = context.deserialize(data, type); if (val != null) { items.add(type.cast(val)); } } return new CouchObjectList<T>(items); }
From source file:org.eclipse.che.api.local.ProjectConfigAdapter.java
License:Open Source License
@Override public ProjectConfig deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(element, ProjectConfigImpl.class); }