Package com.google.gson

Examples of com.google.gson.JsonParseException


          return new Timestamp(parsedDate.getTime());
        }else{       
          return parsedDate; 
        }
      } catch (ParseException e) {
        throw new JsonParseException(e.getMessage());
      }
    }
View Full Code Here


      JsonDeserializationContext context) throws JsonParseException {
   
    JsonObject o = json.getAsJsonObject();
    Set<Entry<String,JsonElement>> entrySet = o.entrySet();
    if (entrySet.size() != 1) {
      throw new JsonParseException("Annotation type with more than one property?");
    }

    Entry<String,JsonElement> kv = entrySet.iterator().next();
    String annClassName = kv.getKey();
    try {
      final Class<?> annClass = Class.forName(annClassName, false, refLoader);
      final Map<Method, Object> methods = Maps.newHashMap();
      for (Entry<String,JsonElement> e : kv.getValue().getAsJsonObject().entrySet()) {
        Method m = annClass.getMethod(e.getKey());
        methods.put(m, context.deserialize(e.getValue(), m.getGenericReturnType()));
      }

      final Method annotationTypeMethod = Annotation.class.getMethod("annotationType");
      InvocationHandler invHandler = new InvocationHandler() {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
          if (method.equals(annotationTypeMethod)) {
            return annClass;
          } else if (methods.containsKey(method)) {
            return methods.get(method);
          }
          return method.getDefaultValue();
        }
      };

      return (Annotation) Proxy.newProxyInstance(refLoader, new Class [] { annClass }, invHandler);
    } catch (Exception 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

      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

    public Color deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
            String value = json.getAsString();
            return new Color((int) Long.parseLong(value, 16));
        }
        throw new JsonParseException("Did not find hexadecimal string for Color value");
    }
View Full Code Here

        private ColliderInfo processAABBShape(JsonDeserializationContext context, JsonObject colliderDef) {
            Vector3f offset = context.deserialize(colliderDef.get(POSITION), Vector3f.class);
            Vector3f extent = context.deserialize(colliderDef.get(EXTENTS), Vector3f.class);
            if (offset == null) {
                throw new JsonParseException("AABB Collider missing position");
            }
            if (extent == null) {
                throw new JsonParseException("AABB Collider missing extents");
            }
            extent.absolute();

            return new ColliderInfo(offset, new BoxShape(extent));
        }
View Full Code Here

        private ColliderInfo processSphereShape(JsonDeserializationContext context, JsonObject colliderDef) {
            Vector3f offset = context.deserialize(colliderDef.get(POSITION), Vector3f.class);
            float radius = colliderDef.get(RADIUS).getAsFloat();
            if (offset == null) {
                throw new JsonParseException("Sphere Collider missing position");
            }

            return new ColliderInfo(offset, new SphereShape(radius));
        }
View Full Code Here

            final Vector3f[] vertices = context.deserialize(meshObj.get("vertices"), Vector3f[].class);
            final Vector3f[] normals = context.deserialize(meshObj.get("normals"), Vector3f[].class);
            final Vector2f[] texCoords = context.deserialize(meshObj.get("texcoords"), Vector2f[].class);

            if (vertices == null) {
                throw new JsonParseException("Vertices missing");
            }
            if (normals == null) {
                throw new JsonParseException("Normals missing");
            }
            if (texCoords == null) {
                throw new JsonParseException("Texcoords missing");
            }
            if (!meshObj.has("faces")) {
                throw new JsonParseException("Faces missing");
            }

            if (vertices.length != normals.length || vertices.length != texCoords.length) {
                throw new JsonParseException("vertices, normals and texcoords must have the same length");
            }

            // Normalise the normals for safety
            for (Vector3f norm : normals) {
                norm.normalize();
            }

            int[][] faces = context.deserialize(meshObj.get("faces"), int[][].class);

            // Convert faces to indices via triangle fan
            TIntList indices = new TIntArrayList();
            for (int[] face : faces) {
                for (int tri = 0; tri < face.length - 2; tri++) {
                    indices.add(face[0]);
                    indices.add(face[tri + 1]);
                    indices.add(face[tri + 2]);
                }
            }

            // Check indices in bounds
            indices.forEach(new TIntProcedure() {
                @Override
                public boolean execute(int value) {
                    if (value < 0 || value >= vertices.length) {
                        throw new JsonParseException("Face value out of range: " + value + ", max vertex is " + (vertices.length - 1));
                    }
                    return true;
                }
            });
View Full Code Here

                String msg = obj.get("msg").getAsString();
                Constructor<Throwable> constructor = clazz.getConstructor(String.class, Throwable.class);
                Throwable th = constructor.newInstance(msg, cause);
                return th;
            } catch (ClassNotFoundException e) {
                throw new JsonParseException("Unable to find " + className);
            } catch (NoSuchMethodException e) {
                throw new JsonParseException("Unable to find constructor for " + className);
            } catch (SecurityException e) {
                throw new JsonParseException("Unable to get over security " + className);
            } catch (InstantiationException e) {
                throw new JsonParseException("Unable to instantiate " + className);
            } catch (IllegalAccessException e) {
                throw new JsonParseException("Illegal access to " + className, e);
            } catch (IllegalArgumentException e) {
                throw new JsonParseException("Illegal argument to " + className, e);
            } catch (InvocationTargetException e) {
                throw new JsonParseException("Cannot invoke " + className, e);
            }
        }
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.