List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:com.kurento.kmf.jsonrpcconnector.JsonUtils.java
License:Open Source License
@Override public Request<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!(json instanceof JsonObject)) { throw new JsonParseException( "Invalid JsonRpc request showning JsonElement type " + json.getClass().getSimpleName()); }/* www. j a va 2s. c om*/ JsonObject jObject = (JsonObject) json; if (!jObject.has(JSON_RPC_PROPERTY)) { throw new JsonParseException( "Invalid JsonRpc request lacking version '" + JSON_RPC_PROPERTY + "' field"); } if (!jObject.get("jsonrpc").getAsString().equals(JSON_RPC_VERSION)) { throw new JsonParseException("Invalid JsonRpc version"); } if (!jObject.has(METHOD_PROPERTY)) { throw new JsonParseException("Invalid JsonRpc request lacking '" + METHOD_PROPERTY + "' field"); } Integer id = null; if (jObject.has(ID_PROPERTY)) { id = jObject.get(ID_PROPERTY).getAsInt(); } ParameterizedType parameterizedType = (ParameterizedType) typeOfT; return new Request<Object>(id, jObject.get(METHOD_PROPERTY).getAsString(), context.deserialize(jObject.get(PARAMS_PROPERTY), parameterizedType.getActualTypeArguments()[0])); }
From source file:com.l.notel.notel.org.redpin.android.json.BaseFingerprintTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)//from w w w.j a v a 2 s . c o m */ public Fingerprint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, Fingerprint.class); }
From source file:com.l.notel.notel.org.redpin.android.json.BaseLocationTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)/*from ww w . j a va2 s. c o m*/ */ public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, Location.class); }
From source file:com.l.notel.notel.org.redpin.android.json.BaseMapTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)//from ww w. j a v a2 s .c o m */ public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, Map.class); }
From source file:com.l.notel.notel.org.redpin.android.json.BaseMeasurementTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)//from w w w . java 2 s . c o m */ public Measurement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, Measurement.class); }
From source file:com.l.notel.notel.org.redpin.android.json.MeasurementTypeAdapter.java
License:Open Source License
/** * @see JsonDeserializer#deserialize(JsonElement, Type, * JsonDeserializationContext)//w w w . j av a 2 s. co m */ 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:com.microsoft.identity.client.internal.configuration.AzureActiveDirectoryAudienceDeserializer.java
License:Open Source License
@Override public AzureActiveDirectoryAudience deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final String methodName = ":deserialize"; JsonObject audienceObject = json.getAsJsonObject(); JsonElement type = audienceObject.get("type"); if (type != null) { switch (type.getAsString()) { case "AzureADMyOrg": Logger.verbose(TAG + methodName, "Type: AzureADMyOrg"); return context.deserialize(audienceObject, AccountsInOneOrganization.class); case "AzureADMultipleOrgs": Logger.verbose(TAG + methodName, "Type: AzureADMultipleOrgs"); return context.deserialize(audienceObject, AnyOrganizationalAccount.class); case "AzureADandPersonalMicrosoftAccount": Logger.verbose(TAG + methodName, "Type: AzureADandPersonalMicrosoftAccount"); return context.deserialize(audienceObject, AllAccounts.class); case "PersonalMicrosoftAccount": Logger.verbose(TAG + methodName, "Type: PersonalMicrosoftAccount"); return context.deserialize(audienceObject, AnyPersonalAccount.class); default://from w ww.j ava 2 s. c om Logger.verbose(TAG + methodName, "Type: Unknown"); return context.deserialize(audienceObject, UnknownAudience.class); } } return null; }
From source file:com.mycompany.gsontesting.EnemyArrayDeserialiser.java
@Override public JsonEnemies deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { //Create generic Json object. final JsonObject jsonObject = json.getAsJsonObject(); CharacterEnemy[] enemy = context.deserialize(jsonObject.get("Enemy"), CharacterEnemy[].class); final JsonEnemies arrObj = new JsonEnemies(); arrObj.setJsonItems(enemy);/*from w w w .j a v a 2 s.c om*/ return arrObj; }
From source file:com.mycompany.gsontesting.ItemArrayDeserialiser.java
@Override public JsonItems deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { //Create generic Json object. final JsonObject jsonObject = json.getAsJsonObject(); Items[] items = context.deserialize(jsonObject.get("Items"), Items[].class); final JsonItems arrObj = new JsonItems(); arrObj.setJsonItems(items);// ww w . j a v a 2s . co m /* Example on how to get a Json field that isn't an array. final JsonElement jsonTitle = jsonObject.get("title"); final String title = jsonTitle.getAsString(); */ /*Example of getting an array at root level. final JsonArray jsonAuthorsArray = jsonObject.get("authors").getAsJsonArray(); final String[] authors = new String[jsonAuthorsArray.size()]; for (int i = 0; i < authors.length; i++) { final JsonElement jsonAuthor = jsonAuthorsArray.get(i); authors[i] = jsonAuthor.getAsString(); } */ return arrObj; }
From source file:com.newtouch.watchman.echarts.utils.json.AxisDeserializer.java
License:Open Source License
@Override /**//w w w . j a v a 2 s . c o m * json,typeOfT,context * * @param json * @param typeOfT * @param context */ public Axis deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); String _type = jsonObject.get("type").getAsString(); AxisType type = AxisType.valueOf(null, _type); Axis axis = null; switch (type) { case category: axis = context.deserialize(jsonObject, CategoryAxis.class); break; case value: axis = context.deserialize(jsonObject, ValueAxis.class); break; case time: axis = context.deserialize(jsonObject, TimeAxis.class); break; } return axis; }