List of usage examples for com.google.gson JsonParseException JsonParseException
public JsonParseException(Throwable cause)
From source file:com.arcbees.vcs.util.PolymorphicTypeAdapter.java
License:Apache License
@Override public T deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(CLASSNAME); String className = jsonPrimitive.getAsString(); Class<?> clazz;/*from ww w.ja v a2s.co m*/ try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new JsonParseException(e.getMessage()); } return context.deserialize(jsonObject.get(VALUE), clazz); }
From source file:com.asakusafw.lang.inspection.json.NodeAdapter.java
License:Apache License
@Override public InspectionNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonObject() == false) { throw new JsonParseException("node must be an object"); //$NON-NLS-1$ }//from ww w . ja v a 2 s .c o m JsonObject object = (JsonObject) json; String id = object.get(KEY_ID).getAsString(); String title = object.get(KEY_TITLE).getAsString(); List<Port> inputs = context.deserialize(object.get(KEY_INPUTS), TYPE_PORTS); List<Port> outputs = context.deserialize(object.get(KEY_OUTPUTS), TYPE_PORTS); Map<String, String> properties = context.deserialize(object.get(KEY_PROPERTIES), TYPE_PROPERTIES); List<InspectionNode> elements = context.deserialize(object.get(KEY_ELEMENTS), TYPE_NODES); InspectionNode result = new InspectionNode(id, title); put(inputs, result.getInputs()); put(outputs, result.getOutputs()); result.getProperties().putAll(properties); put(elements, result.getElements()); return result; }
From source file:com.asakusafw.lang.inspection.json.PortAdapter.java
License:Apache License
@Override public InspectionNode.Port deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonObject() == false) { throw new JsonParseException("port must be an object"); //$NON-NLS-1$ }/*from w ww . j a v a 2 s . c o m*/ JsonObject object = (JsonObject) json; String id = object.get(KEY_ID).getAsString(); Map<String, String> properties = context.deserialize(object.get(KEY_PROPERTIES), TYPE_PROPERTIES); Set<PortReference> opposites = context.deserialize(object.get(KEY_OPPOSITES), TYPE_REFERENCES); InspectionNode.Port result = new InspectionNode.Port(id); result.getProperties().putAll(properties); result.getOpposites().addAll(opposites); return result; }
From source file:com.asakusafw.lang.inspection.json.PortReferenceAdapter.java
License:Apache License
@Override public InspectionNode.PortReference deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonArray() == false) { throw new JsonParseException("port reference must be an array"); //$NON-NLS-1$ }/* ww w . j a v a 2 s . com*/ JsonArray array = (JsonArray) json; if (array.size() != 2) { throw new JsonParseException("port reference must have just 2 elements"); //$NON-NLS-1$ } String nodeId = array.get(0).getAsString(); String portId = array.get(1).getAsString(); return new PortReference(nodeId, portId); }
From source file:com.atlauncher.adapter.ColorTypeAdapter.java
License:Open Source License
@Override public Color read(JsonReader reader) throws IOException { reader.beginObject();//from ww w. ja va2s . c om String next = reader.nextName(); if (!next.equalsIgnoreCase("value")) { throw new JsonParseException("Key " + next + " isnt a valid key"); } String hex = reader.nextString(); reader.endObject(); int[] rgb = toRGB(clamp(hex.substring(1))); return new Color(rgb[0], rgb[1], rgb[2]); }
From source file:com.auth0.android.lock.internal.configuration.GsonDeserializer.java
License:Open Source License
<U> U requiredValue(String name, Type type, JsonObject object, JsonDeserializationContext context) throws JsonParseException { U value = context.deserialize(object.get(name), type); if (value == null) { throw new JsonParseException(String.format("Missing required attribute %s", name)); }/*ww w .j a v a2 s . c o m*/ return value; }
From source file:com.auth0.android.lock.internal.configuration.GsonDeserializer.java
License:Open Source License
void assertJsonObject(JsonElement jsonObject) throws JsonParseException { if (jsonObject.isJsonNull() || !jsonObject.isJsonObject()) { throw new JsonParseException("Received json is not a valid json object."); }/* w ww .j a v a2s .c o m*/ }
From source file:com.autoclavestudios.jbower.config.internal.JsonRegistryTranslator.java
License:Apache License
@Override public Registry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Registry registry = new Registry(); try {// www. ja v a 2 s . c o m if (json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); if (jsonObject.has("search")) registry.search(ConvertToArray(jsonObject.get("search").getAsJsonArray())); if (jsonObject.has("publish")) registry.publish(ConvertToArray(jsonObject.get("publish").getAsJsonArray())); if (jsonObject.has("register")) registry.register(ConvertToArray(jsonObject.get("register").getAsJsonArray())); } else if (json.isJsonPrimitive()) { registry.all(json.getAsString()); } else { throw new JsonParseException("Registry object is not a Json Object or Primitive"); } } catch (MalformedURLException e) { logger.error("Malformed URL: {}", json.getAsString()); } return registry; }
From source file:com.azure.webapi.DateSerializer.java
License:Open Source License
/** * Deserializes a JsonElement containing an ISO-8601 formatted date *///from www . ja v a2 s . c o m @Override public Date deserialize(JsonElement element, Type type, JsonDeserializationContext ctx) throws JsonParseException { String strVal = element.getAsString(); try { return deserialize(strVal); } catch (ParseException e) { throw new JsonParseException(e); } }
From source file:com.azure.webapi.LoginManager.java
License:Open Source License
/** * Creates a User based on a Windows Azure Mobile Service JSON object * containing a UserId and Authentication Token * //w w w. ja va 2 s . com * @param json * JSON object used to create the User * @return The created user if it is a valid JSON object. Null otherwise * @throws MobileServiceException */ private MobileServiceUser createUserFromJSON(JsonObject json) throws MobileServiceException { if (json == null) { throw new IllegalArgumentException("json can not be null"); } // If the JSON object is valid, create a MobileServiceUser object if (json.has(USER_JSON_PROPERTY)) { JsonObject jsonUser = json.getAsJsonObject(USER_JSON_PROPERTY); if (!jsonUser.has(USERID_JSON_PROPERTY)) { throw new JsonParseException(USERID_JSON_PROPERTY + " property expected"); } String userId = jsonUser.get(USERID_JSON_PROPERTY).getAsString(); MobileServiceUser user = new MobileServiceUser(userId); if (!json.has(TOKEN_JSON_PARAMETER)) { throw new JsonParseException(TOKEN_JSON_PARAMETER + " property expected"); } user.setAuthenticationToken(json.get(TOKEN_JSON_PARAMETER).getAsString()); return user; } else { // If the JSON contains an error property show it, otherwise raise // an error with JSON content if (json.has("error")) { throw new MobileServiceException(json.get("error").getAsString()); } else { throw new JsonParseException(json.toString()); } } }