List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:org.redpin.server.standalone.json.BaseSpinnerDataTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) *//*from w ww . ja v a 2 s. co m*/ @Override public SpinnerData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, SpinnerData.class); }
From source file:org.redpin.server.standalone.json.BaseTaskTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) *//*ww w.j av a 2 s. co m*/ @Override public Task deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, Task.class); }
From source file:org.redpin.server.standalone.json.BaseUserTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)//from ww w . ja va 2 s .c o m */ @Override public User deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, User.class); }
From source file:org.redpin.server.standalone.json.MeasurementTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) *//*from w w w . java 2 s . co m*/ @Override public Measurement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // get all json elements in order to deserialize them separately JsonObject obj = json.getAsJsonObject(); JsonElement json_timestamp = obj.get("timestamp"); JsonElement json_wifi = obj.get("wifiReadings"); JsonElement json_gsm = obj.get("gsmReadings"); JsonElement json_bluetooth = obj.get("bluetoothReadings"); // init vectors Vector<WiFiReading> wifi = new Vector<WiFiReading>(); Vector<GSMReading> gsm = new Vector<GSMReading>(); Vector<BluetoothReading> bluetooth = new Vector<BluetoothReading>(); // deserialize reading vectors Type listType; if (json_wifi != null) { listType = new TypeToken<Vector<WiFiReading>>() { }.getType(); Collection<WiFiReading> wificol = context.deserialize(json_wifi, listType); wifi.addAll(wificol); } if (json_gsm != null) { listType = new TypeToken<Vector<GSMReading>>() { }.getType(); Collection<GSMReading> gsmcol = context.deserialize(json_gsm, listType); gsm.addAll(gsmcol); } if (json_bluetooth != null) { listType = new TypeToken<Vector<BluetoothReading>>() { }.getType(); Collection<BluetoothReading> bluetoothcol = context.deserialize(json_bluetooth, listType); bluetooth.addAll(bluetoothcol); } // create deserialized measurement Measurement m = new Measurement(gsm, wifi, bluetooth); if (json_timestamp != null) { m.setTimestamp((Long) context.deserialize(json_timestamp, Long.class)); } return m; }
From source file:org.smartparam.serializer.metadata.LevelJsonDeserializer.java
License:Apache License
public Level deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { return context.deserialize(json, DeserializedLevel.class); }
From source file:org.sprintapi.hyperdata.gson.GsonHyperDataDeserializer.java
License:Apache License
@Override public HyperMap deserialize(JsonElement json, Type arg1, JsonDeserializationContext ctx) throws JsonParseException { if (!json.isJsonObject()) { throw new JsonParseException( "Unexpected " + json.getClass().getSimpleName() + ", expected JsonObject object."); }//from ww w.j a va 2 s .c o m JsonObject jsonObject = json.getAsJsonObject(); HyperHashMap hdata = null; if (jsonObject != null) { hdata = new HyperHashMap(); final Set<Entry<String, JsonElement>> entrySet = jsonObject.entrySet(); if (entrySet != null) { Map<String, Object> metadata = null; for (Entry<String, JsonElement> entry : entrySet) { if (entry.getKey().startsWith(Constants.META_CHAR)) { if (metadata == null) { metadata = new HashMap<String, Object>(); } JsonElement value = entry.getValue(); if (value != null) { metadata.put(entry.getKey().substring(1), ctx.deserialize(value, (value.isJsonObject() && value.getAsJsonObject().has(Constants.META_CHAR.concat(HREF_KEY))) ? HyperMap.class : Object.class)); } } else { JsonElement value = entry.getValue(); if (value != null) { hdata.put(entry.getKey(), ctx.deserialize(value, (value.isJsonObject() && value.getAsJsonObject().has(Constants.META_CHAR.concat(HREF_KEY))) ? HyperMap.class : Object.class)); } } } hdata.setMetadata(metadata); } } return hdata; }
From source file:org.stjs.server.json.gson.JSArrayAdapter.java
License:Apache License
@Override public Array<?> deserialize(JsonElement elem, Type type, JsonDeserializationContext ctx) throws JsonParseException { if (elem == null) { return null; }//from w ww .j a v a 2s . c om JsonArray js = elem.getAsJsonArray(); Type elementType = (type instanceof ParameterizedType) ? ((ParameterizedType) type).getActualTypeArguments()[0] : Object.class; Array<Object> array = JSCollections.$array(); for (int i = 0; i < js.size(); ++i) { array.push(ctx.deserialize(js.get(i), elementType)); } return array; }
From source file:org.stjs.server.json.gson.JSMapAdapter.java
License:Apache License
@Override public Map<?, ?> deserialize(JsonElement elem, Type type, JsonDeserializationContext ctx) throws JsonParseException { if (elem == null) { return null; }// w w w . j a v a 2 s . c om JsonObject js = elem.getAsJsonObject(); Type valueType = (type instanceof ParameterizedType) ? ((ParameterizedType) type).getActualTypeArguments()[1] : Object.class; Map<String, Object> map = JSCollections.$map(); for (java.util.Map.Entry<String, JsonElement> entry : js.entrySet()) { map.$put(entry.getKey(), ctx.deserialize(entry.getValue(), valueType)); } return map; }
From source file:org.terasology.logic.behavior.core.BehaviorTreeBuilder.java
License:Apache License
private BehaviorNode getPrimitiveNode(JsonElement json, JsonDeserializationContext context) { String type = json.getAsString(); BehaviorNode node = createNode(type); if (actions.containsKey(type)) { Action action = context.deserialize(new JsonObject(), actions.get(type)); addAction((ActionNode) node, action); } else if (decorators.containsKey(type)) { Action action = context.deserialize(new JsonObject(), decorators.get(type)); addAction((ActionNode) node, action); }//from w w w . j a va2 s . co m return node; }
From source file:org.terasology.logic.behavior.core.BehaviorTreeBuilder.java
License:Apache License
private BehaviorNode getCompositeNode(JsonElement json, JsonDeserializationContext context) { String type;//from w ww. j av a 2s .co m JsonObject obj = json.getAsJsonObject(); Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next(); type = entry.getKey(); JsonElement jsonElement = entry.getValue(); BehaviorNode node = createNode(type); if (actions.containsKey(type)) { Action action = context.deserialize(jsonElement, actions.get(type)); addAction((ActionNode) node, action); } else if (decorators.containsKey(type)) { Action action = context.deserialize(jsonElement, decorators.get(type)); addAction((ActionNode) node, action); JsonElement childJson = jsonElement.getAsJsonObject().get("child"); BehaviorNode child = context.deserialize(childJson, BehaviorNode.class); node.insertChild(0, child); } else if (jsonElement.isJsonArray()) { List<BehaviorNode> children = context.deserialize(jsonElement, new TypeToken<List<BehaviorNode>>() { }.getType()); for (int i = 0; i < children.size(); i++) { BehaviorNode child = children.get(i); node.insertChild(i, child); } } return node; }