Package com.google.gson

Examples of com.google.gson.JsonParseException


    }

    @Override
    public Date deserialize (JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
        if (!(json instanceof JsonPrimitive)) {
            throw new JsonParseException("Date was not string: " + json);
        }
        if (type != Date.class) {
            throw new IllegalArgumentException(getClass() + " cannot deserialize to " + type);
        }
        String value = json.getAsString();
View Full Code Here


                    if (kind != null) {
                        return kind;
                    }
                }
            }
            throw new JsonParseException(MessageFormat.format(
                    "Invalid JobStatus.Kind: {0}",
                    json));
        }
View Full Code Here

    @Override
    public Vector deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        JsonArray jsonArray = json.getAsJsonArray();
        if (jsonArray.size() != 3) {
            throw new JsonParseException("Expected array of 3 length for Vector");
        }

        double x = jsonArray.get(0).getAsDouble();
        double y = jsonArray.get(1).getAsDouble();
        double z = jsonArray.get(2).getAsDouble();
View Full Code Here

      String encodedData = properties.get(Attachment.DATA);
      if (encodedData != null) {
        try {
          data = Base64.decodeBase64(encodedData.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
          throw new JsonParseException("Couldn't convert to utf-8", e);
        }
      }
      result = new Attachment(properties, data);
    } else if (type == ElementType.LINE) {
      result = new Line(properties);
View Full Code Here

    JsonArray events = new JsonArray();
    for (Event event : src.getEvents()) {
      try {
        events.add(EventSerializer.serialize(event, context));
      } catch (EventSerializationException e) {
        throw new JsonParseException(e);
      }
    }
    result.add(EVENTS_TAG, events);

    result.add(WAVELET_TAG, context.serialize(src.getWaveletData()));
View Full Code Here

    for (JsonElement element : eventsArray) {
      JsonObject eventObject = element.getAsJsonObject();
      try {
        events.add(EventSerializer.deserialize(wavelet, result, eventObject, context));
      } catch (EventSerializationException e) {
        throw new JsonParseException(e.getMessage());
      }
    }
    result.setEvents(events);
    return result;
  }
View Full Code Here

  private static class MapDecoder implements JsonDeserializer<Map<String, String>> {
    @Override
    public Map<String, String> deserialize(JsonElement arg0, Type arg1,
        JsonDeserializationContext arg2) throws JsonParseException {
      if (!arg0.isJsonObject()) {
        throw new JsonParseException(arg0.toString() + " is not Json Object, cannot convert to map");
      }
      JsonObject objs = arg0.getAsJsonObject();
      Map<String, String> map = new HashMap<String ,String>();
      for (Entry<String, JsonElement> e : objs.entrySet()) {
        if (!e.getValue().isJsonPrimitive()) {
          throw new JsonParseException(e.getValue().toString() + " is not a Json primitive," + arg0 + " can not convert to map");
        }
        map.put(e.getKey(), e.getValue().getAsString());
      }
      return map;
    }
View Full Code Here

                JsonDeserializationContext context) throws JsonParseException {
            JsonObject jsonObject = jsonElement.getAsJsonObject();
            NatRule natRule = null;
           
            if (!jsonObject.has("type")) {
                throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object");
            }
           
            String natRuleType = jsonObject.get("type").getAsString();
            if ("SourceNatRule".equals(natRuleType)) {
                return context.deserialize(jsonElement, SourceNatRule.class);
            }
            else if ("DestinationNatRule".equals(natRuleType)) {
                return context.deserialize(jsonElement, DestinationNatRule.class);
            }
           
            throw new JsonParseException("Failed to deserialize type \"" + natRuleType + "\"");
        }
View Full Code Here

        }
        // Invoke the build method to return the final proto
        return (GeneratedMessage) getCachedMethod(builderClass, "build")
        .invoke(protoBuilder);
      } catch (SecurityException e) {
        throw new JsonParseException(e);
      } catch (NoSuchMethodException e) {
        throw new JsonParseException(e);
      } catch (IllegalArgumentException e) {
        throw new JsonParseException(e);
      } catch (IllegalAccessException e) {
        throw new JsonParseException(e);
      } catch (InvocationTargetException e) {
        throw new JsonParseException(e);
      } catch (NoSuchFieldException e) {
        throw new JsonParseException(e);
      }
    }
View Full Code Here

    // (drt24) Since android ships with an ancient version of org.apache.commons.codec which
    // overrides any version we ship we have to use old deprecated methods.
    if (Base64.isArrayByteBase64(jsonBytes)) {
      return ByteString.copyFrom(Base64.decodeBase64(jsonBytes));
    } else {
      throw new JsonParseException("JSON element is not correctly base64 encoded.");
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.