Package com.google.gson

Examples of com.google.gson.JsonParseException


    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    Class<?> cl;
    try {
      cl = ccl.loadClass(klass);
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(e);
    }
    return (Vector) gson.fromJson(vector, cl);
  }
View Full Code Here


    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    Class<? extends Matrix> cl;
    try {
      cl = (Class<? extends Matrix>) ccl.loadClass(klass);
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(e);
    }

    if (obj.get(MATRIX).isJsonPrimitive()) {
      String matrix = obj.get(MATRIX).getAsString();
      Gson gson = AbstractMatrix.gson();
View Full Code Here

    String className = jsonObj.get(CLASS_META_KEY).getAsString();
    try {
      Class<?> clz = Class.forName(className);
      return jsonDeserializationContext.deserialize(jsonElement, clz);
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(e);
    }
  }
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

      final JsonDeserializationContext context) throws JsonParseException {
    if (json.isJsonNull()) {
      return null;
    }
    if (!json.isJsonArray()) {
      throw new JsonParseException("Expected array for Edit type");
    }

    final JsonArray o = (JsonArray) json;
    final int cnt = o.size();
    if (cnt < 4 || cnt % 4 != 0) {
      throw new JsonParseException("Expected array of 4 for Edit type");
    }

    if (4 == cnt) {
      return new Edit(get(o, 0), get(o, 1), get(o, 2), get(o, 3));
    }
View Full Code Here

  private static int get(final JsonArray a, final int idx)
      throws JsonParseException {
    final JsonElement v = a.get(idx);
    if (!v.isJsonPrimitive()) {
      throw new JsonParseException("Expected array of 4 for Edit type");
    }
    final JsonPrimitive p = (JsonPrimitive) v;
    if (!p.isNumber()) {
      throw new JsonParseException("Expected array of 4 for Edit type");
    }
    return p.getAsInt();
  }
View Full Code Here

            {
                result = primitive.getAsBoolean();
            }
            else
            {
                throw new JsonParseException("Unsupported primitive value " + primitive);
            }
            return new SimplePropertyValue(result);
        }
        else if (json.isJsonArray())
        {
            JsonArray array = json.getAsJsonArray();
            List<Object> result = new ArrayList<Object>(array.size());
            for (JsonElement element : array)
            {
                result.add(context.deserialize(element, Object.class));
            }
            return new SimplePropertyValue(result);
        }
        else if (json.isJsonObject())
        {
            JsonObject object = json.getAsJsonObject();
            JsonElement defElement = object.getAsJsonPrimitive(DEF_FIELD);
            Class<?> classInstance = null;
            if (defElement != null)
            {
                try
                {
                    classInstance = _factory.getPropertyValueClass(defElement.getAsString());
                }
                catch (ClassNotFoundException e)
                {
                    // ignore
                }
            }
            if (classInstance == null)
            {
                Map<String, Object> result = new HashMap<String, Object>();
                for (Map.Entry<String, JsonElement> entry : object.entrySet())
                {
                    Object value = context.deserialize(entry.getValue(), Object.class);
                    result.put(entry.getKey(), value);
                }
                return new SimplePropertyValue(result);
            }
            else
            {
                return context.deserialize(json, classInstance);
            }
        }
        else
        {
            throw new JsonParseException("Unsupported JSON type " + json);
        }
    }
View Full Code Here

    assert parent != null;
    assert !StringUtils.isEmpty(elementName);
   
    JsonElement element = parent.get( elementName );
    if( !element.isJsonPrimitive() ) {
      throw new JsonParseException( "Element + '" + elementName + "' must be a valid integer");
    }
    JsonPrimitive primitiveElement = (JsonPrimitive)element;
    if( !primitiveElement.isNumber()) {
      throw new JsonParseException( "Element + '" + elementName + "' must be a valid integer");
    }
    return primitiveElement.getAsInt();
  }
View Full Code Here

      assert json != null;
      assert context != null;
      assert typeOfT != null;
     
      if( !json.isJsonObject() ) {
        throw new JsonParseException( "A GregorianCalendar must be a JSON object");
      }
     
      JsonObject jsonObject = json.getAsJsonObject();
      int year = getIntValue( jsonObject, "year" );
      int month = getIntValue( jsonObject, "month" ); // GregorianCalendar stores month as realMonth-1 (first month is 0!)
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.