Package com.metaparadigm.jsonrpc

Examples of com.metaparadigm.jsonrpc.UnmarshallException


  public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object jso)
      throws UnmarshallException {
    try {
      unmarshal((String) jso);
    } catch (Exception e) {
      throw new UnmarshallException("cannot convert object " + jso + " to type " + clazz.getName());
    }
    return ObjectMatch.OKAY;
  }
View Full Code Here


  public Object unmarshall(SerializerState state, Class clazz, Object jso) throws UnmarshallException {
    try {
      return unmarshal((String) jso);
    } catch (Exception e) {
      log.error("cannot convert object " + jso + " to type " + clazz.getName(), e);
      throw new UnmarshallException("cannot convert object " + jso + " to type " + clazz.getName());
    }
  }
View Full Code Here

  public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;
    String type = jso.getString(ATTRIBUTE_TYPE);
    if (type == null) {
      throw new UnmarshallException("no type hint");
    }
    int srid = jso.getInt(ATTRIBUTE_SRID);
    if (srid <= 0) {
      throw new UnmarshallException("no srid");
    }
    int precision = jso.getInt(ATTRIBUTE_PRECISION);
    if (precision <= 0) {
      throw new UnmarshallException("no precision");
    }
    if (!(type.equals(org.geomajas.geometry.Geometry.POINT) ||
        type.equals(org.geomajas.geometry.Geometry.LINE_STRING) ||
        type.equals(org.geomajas.geometry.Geometry.POLYGON) ||
        type.equals(org.geomajas.geometry.Geometry.LINEAR_RING) ||
        type.equals(org.geomajas.geometry.Geometry.MULTI_LINE_STRING) ||
        type.equals(org.geomajas.geometry.Geometry.MULTI_POLYGON))) {
      throw new UnmarshallException(type + " is not a supported geometry");
    }
    JSONArray coordinates = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (coordinates == null) {
      throw new UnmarshallException("coordinates missing");
    }
    return ObjectMatch.OKAY;
  }
View Full Code Here

  public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;
    String type = jso.getString(ATTRIBUTE_TYPE);
    if (type == null) {
      throw new UnmarshallException("no type hint");
    }
    int srid = jso.getInt(ATTRIBUTE_SRID);
    int precision = jso.getInt(ATTRIBUTE_PRECISION);
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(Math.pow(10, precision)), srid);
View Full Code Here

    JSONArray coords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    Coordinate[] coordinates = new Coordinate[coords.length()];
    for (int i = 0; i < coords.length(); i++) {
      JSONObject nextCoord = coords.getJSONObject(i);
      if (nextCoord == null) {
        throw new UnmarshallException("inner coordinate missing");
      }
      coordinates[i] = new Coordinate(nextCoord.getDouble("x"), nextCoord.getDouble("y"));
    }
    coordinates = checkIfClosed(coordinates);
    return factory.createLinearRing(coordinates);
View Full Code Here

  private LineString createLineString(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    LineString geometry;
    JSONArray jsonCoords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (jsonCoords == null) {
      throw new UnmarshallException("coordinates missing");
    }
    Coordinate[] coordinates = new Coordinate[jsonCoords.length()];
    for (int i = 0; i < jsonCoords.length(); i++) {
      JSONObject nextCoord = jsonCoords.getJSONObject(i);
      if (nextCoord == null) {
        throw new UnmarshallException("inner coordinate missing");
      }
      coordinates[i] = new Coordinate(nextCoord.getDouble("x"), nextCoord.getDouble("y"));
    }
    geometry = new LineString(new CoordinateArraySequence(coordinates), factory);
    return geometry;
View Full Code Here

  private Point createPoint(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    Point geometry;
    JSONArray jsonCoords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (jsonCoords == null) {
      throw new UnmarshallException("coordinates missing");
    }
    if (jsonCoords.length() != 1) {
      throw new UnmarshallException("wrong number of coordinates " + jsonCoords.length() + " for point");
    }
    JSONObject coord = jsonCoords.getJSONObject(0);
    if (coord == null) {
      throw new UnmarshallException("inner coordinate missing");
    }

    Coordinate coordinate = new Coordinate(coord.getDouble("x"), coord.getDouble("y"));
    geometry = new Point(new CoordinateArraySequence(new Coordinate[] {coordinate}), factory);
    return geometry;
View Full Code Here

  public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object jso) throws UnmarshallException {
    try {
      toEnum(clazz, jso);
    } catch (IllegalArgumentException e) {
      throw new UnmarshallException("Not a valid enum string");
    }
    return ObjectMatch.OKAY;
  }
View Full Code Here

      if (jso == null || "".equals(jso)) {
        return null;
      }
      return toEnum(clazz, jso);
    } catch (IllegalArgumentException nfe) {
      throw new UnmarshallException("cannot convert object " + jso + " to type " + clazz.getName());
    }
  }
View Full Code Here

  public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object jso)
      throws UnmarshallException {
    try {
      toBigNumber(clazz, jso);
    } catch (NumberFormatException e) {
      throw new UnmarshallException("not a number");
    }
    return ObjectMatch.OKAY;
  }
View Full Code Here

TOP

Related Classes of com.metaparadigm.jsonrpc.UnmarshallException

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.