List of usage examples for com.google.gson JsonParseException JsonParseException
public JsonParseException(Throwable cause)
From source file:cl.niclabs.tscrypto.common.messages.TSMessageParser.java
License:Open Source License
private TSMessage parseQuery(String type, String version, JsonElement json, JsonDeserializationContext context) { switch (type) { case "ping-query": return context.deserialize(json, PingQuery.class); case "signShare-query": return context.deserialize(json, SignShareQuery.class); case "sendKey-query": return context.deserialize(json, SendKeyQuery.class); case "deleteKey-query": return context.deserialize(json, DeleteKeyQuery.class); }// w ww . j a v a2s.c o m throw new JsonParseException("Illegal TSMessage Query type/version:" + type + "/" + version); }
From source file:cl.niclabs.tscrypto.common.messages.TSMessageParser.java
License:Open Source License
private TSMessage parseAnswer(String type, String version, JsonElement json, JsonDeserializationContext context) { switch (type) { case "ping-answer": return context.deserialize(json, PingAnswer.class); case "signShare-answer": return context.deserialize(json, SignShareAnswer.class); case "sendKey-answer": return context.deserialize(json, SendKeyAnswer.class); case "deleteKey-answer": return context.deserialize(json, DeleteKeyAnswer.class); }//from w w w . j a v a 2s .c o m throw new JsonParseException("Illegal TSMessage Answer type/version:" + type + "/" + version); }
From source file:cmput301.f13t01.elasticsearch.InterfaceAdapter.java
License:GNU General Public License
private Type typeForName(final JsonElement typeElem) { try {// www. ja v a 2s . c o m return Class.forName(typeElem.getAsString()); } catch (ClassNotFoundException e) { throw new JsonParseException(e); } }
From source file:cmput301.f13t01.elasticsearch.InterfaceAdapter.java
License:GNU General Public License
private JsonElement get(final JsonObject wrapper, String memberName) { final JsonElement elem = wrapper.get(memberName); if (elem == null) throw new JsonParseException( "no '" + memberName + "' member found in what was expected to be an interface wrapper"); return elem;/*from w ww . ja va 2 s .co m*/ }
From source file:co.cask.cdap.common.conf.PluginClassDeserializer.java
License:Apache License
@Override public PluginClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonObject()) { throw new JsonParseException("PluginClass should be a JSON Object"); }//from w w w .ja v a2 s.c om JsonObject jsonObj = json.getAsJsonObject(); String type = jsonObj.has("type") ? jsonObj.get("type").getAsString() : Plugin.DEFAULT_TYPE; String name = getRequired(jsonObj, "name").getAsString(); String description = jsonObj.has("description") ? jsonObj.get("description").getAsString() : ""; String className = getRequired(jsonObj, "className").getAsString(); Set<String> endpointsSet = new HashSet<>(); if (jsonObj.has("endpoints")) { endpointsSet = context.deserialize(jsonObj.get("endpoints"), ENDPOINTS_TYPE); } Map<String, PluginPropertyField> properties = jsonObj.has("properties") ? context.<Map<String, PluginPropertyField>>deserialize(jsonObj.get("properties"), PROPERTIES_TYPE) : ImmutableMap.<String, PluginPropertyField>of(); return new PluginClass(type, name, description, className, null, properties, endpointsSet); }
From source file:co.cask.cdap.common.conf.PluginClassDeserializer.java
License:Apache License
private JsonElement getRequired(JsonObject jsonObj, String name) { if (!jsonObj.has(name)) { throw new JsonParseException("Property '" + name + "' is missing from PluginClass."); }//from w w w.j a va 2s . c om return jsonObj.get(name); }
From source file:co.cask.cdap.common.zookeeper.coordination.ResourceAssignmentTypeAdapter.java
License:Apache License
@Override public ResourceAssignment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonObject()) { throw new JsonParseException("Expect a json object, got " + json); }// ww w . ja v a 2 s.c o m JsonObject jsonObj = json.getAsJsonObject(); String name = jsonObj.get("name").getAsString(); Multimap<Discoverable, PartitionReplica> assignments = TreeMultimap .create(DiscoverableComparator.COMPARATOR, PartitionReplica.COMPARATOR); JsonArray assignmentsJson = context.deserialize(jsonObj.get("assignments"), JsonArray.class); for (JsonElement element : assignmentsJson) { if (!element.isJsonArray()) { throw new JsonParseException("Expect a json array, got " + element); } JsonArray entryJson = element.getAsJsonArray(); if (entryJson.size() != 2) { throw new JsonParseException("Expect json array of size = 2, got " + entryJson.size()); } Discoverable key = context.deserialize(entryJson.get(0), Discoverable.class); PartitionReplica value = context.deserialize(entryJson.get(1), PartitionReplica.class); assignments.put(key, value); } return new ResourceAssignment(name, assignments); }
From source file:co.cask.cdap.internal.app.runtime.artifact.ArtifactRangeCodec.java
License:Apache License
@Override public ArtifactRange deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try {//from w w w . ja v a 2s .co m return ArtifactRange.parse(json.getAsString()); } catch (InvalidArtifactRangeException e) { throw new JsonParseException(e); } }
From source file:co.cask.cdap.proto.codec.EntityIdTypeAdapter.java
License:Apache License
@Override public EntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject map = json.getAsJsonObject(); JsonElement entityTypeJson = map.get("entity"); if (entityTypeJson == null) { throw new JsonParseException("Expected entity in EntityId JSON"); }//from w ww. ja v a2 s.c o m String entityTypeString = entityTypeJson.getAsString(); EntityType type = EntityType.valueOf(entityTypeString); if (type == null) { throw new JsonParseException("Invalid entity: " + entityTypeString); } return context.deserialize(json, type.getIdClass()); }
From source file:co.cask.cdap.proto.codec.IdTypeAdapter.java
License:Apache License
@Override public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject map = json.getAsJsonObject(); JsonElement elementTypeJson = map.get("elementType"); if (elementTypeJson == null) { throw new JsonParseException("Expected elementType in Id JSON"); }//from ww w .j a v a 2 s. c om String elementTypeString = elementTypeJson.getAsString(); EntityType type = EntityType.valueOf(elementTypeString); if (type == null) { throw new JsonParseException("Invalid elementType: " + elementTypeString); } return context.deserialize(json, type.getIdClass()); }