Package org.json

Examples of org.json.JSONObject$Null


        ((jsonClazz == null || jsonClazz == JSONObject.class) && Geometry.class
            .isAssignableFrom(clazz)));
  }

  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


    }
    return ObjectMatch.OKAY;
  }

  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);

    Geometry geometry = null;
    if (type.equals(org.geomajas.geometry.Geometry.POINT)) {
      geometry = createPoint(factory, jso);
View Full Code Here

    }
    return geometry;
  }

  private Polygon createPolygon(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    JSONObject jsoShell = jso.getJSONObject("shell");
    LinearRing shell = createLinearRing(factory, jsoShell);

    JSONArray holeArray = jso.getJSONArray("holes");
    LinearRing[] holes = new LinearRing[holeArray.length()];
    for (int i = 0; i < holeArray.length(); i++) {
      JSONObject jsoHole = holeArray.getJSONObject(i);
      holes[i] = createLinearRing(factory, jsoHole);
    }
    return factory.createPolygon(shell, holes);
  }
View Full Code Here

  private LinearRing createLinearRing(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    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

    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

      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

    }
    return factory.createMultiLineString(lineStrings);
  }

  public Object marshall(SerializerState state, Object o) throws MarshallException {
    JSONObject obj;
    Geometry geometry = (Geometry) o;

    if (geometry instanceof Point) {
      obj = fromPoint((Point) geometry);
    } else if (geometry instanceof LineString) {
View Full Code Here

      jso.put(ATTRIBUTE_PRECISION, precision);
    }
  }

  private JSONObject fromPoint(Point p) {
    JSONObject jso = new JSONObject();
    JSONArray coordinates = new JSONArray();
    PrecisionModel precisionmodel = p.getPrecisionModel();
    coordinates.put(precisionmodel.makePrecise(p.getX()));
    coordinates.put(precisionmodel.makePrecise(p.getY()));
    putBasics(jso, p);
    jso.put(ATTRIBUTE_COORDINATES, coordinates);
    return jso;
  }
View Full Code Here

    jso.put(ATTRIBUTE_COORDINATES, coordinates);
    return jso;
  }

  private JSONObject fromMultiPoint(MultiPoint mp) {
    JSONObject jso = new JSONObject();
    JSONArray polys = new JSONArray();
    for (int i = 0; i < mp.getNumGeometries(); i++) {
      polys.put(fromPoint((Point) mp.getGeometryN(i)));
    }
    jso.put("points", polys);
    putBasics(jso, mp);
    return jso;
  }
View Full Code Here

    return jso;
  }

  private JSONObject fromLineString(LineString ls) {
    PrecisionModel precisionmodel = ls.getPrecisionModel();
    JSONObject jso = new JSONObject();
    JSONArray coordinates = new JSONArray();
    for (int i = 0; i < ls.getCoordinates().length; i++) {
      coordinates.put(precisionmodel.makePrecise(ls.getCoordinates()[i].x));
      coordinates.put(precisionmodel.makePrecise(ls.getCoordinates()[i].y));
    }
    putBasics(jso, ls);
    jso.put(ATTRIBUTE_COORDINATES, coordinates);
    return jso;
  }
View Full Code Here

TOP

Related Classes of org.json.JSONObject$Null

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.