Package com.metaparadigm.jsonrpc

Examples of com.metaparadigm.jsonrpc.UnmarshallException


      if (jso == null || "".equals(jso)) {
        return null;
      }
      return toBigNumber(clazz, jso);
    } catch (NumberFormatException 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 {
      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

    JSONObject jso = (JSONObject) o;
    BeanData bd;
    try {
      bd = getBeanData(clazz);
    } catch (IntrospectionException e) {
      throw new UnmarshallException(clazz.getName() + " is not a bean");
    }

    int match = 0, mismatch = 0;
    Iterator i = bd.writableProps.entrySet().iterator();
    while (i.hasNext()) {
      Map.Entry ent = (Map.Entry) i.next();
      String prop = (String) ent.getKey();
      if (jso.has(prop)) {
        match++;
      } else {
        mismatch++;
      }
    }
    if (match == 0) {
      throw new UnmarshallException("bean has no matches");
    }

    ObjectMatch m = null, tmp;
    i = jso.keys();
    while (i.hasNext()) {
      String field = (String) i.next();
      Method setMethod = bd.writableProps.get(field);
      if (setMethod != null) {
        try {
          Class[] param = setMethod.getParameterTypes();
          if (param.length != 1) {
            throw new UnmarshallException("bean " + clazz.getName() + " method "
                + setMethod.getName() + " does not have one arg");
          }
          tmp = ser.tryUnmarshall(state, param[0], jso.get(field));
          if (m == null) {
            m = tmp;
          } else {
            m = m.max(tmp);
          }
        } catch (UnmarshallException e) {
          throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage());
        }
      } else {
        mismatch++;
      }
    }
View Full Code Here

    JSONObject jso = (JSONObject) o;
    BeanData bd;
    try {
      bd = getBeanData(clazz);
    } catch (IntrospectionException e) {
      throw new UnmarshallException(clazz.getName() + " is not a bean");
    }
    log.debug("instantiating {}", clazz.getName());
    Object instance;
    try {
      String beanName = beanNameSimplifier.simplify(clazz.getName());
      if (applicationContext.containsBean(beanName)) {
        instance = applicationContext.getBean(beanName);
      } else {
        log.debug("instantiating " + clazz.getName());
        instance = clazz.newInstance();
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new UnmarshallException("can't instantiate bean " + clazz.getName() + ": " + e.getMessage());
    }
    Object[] invokeArgs = new Object[1];
    Object fieldVal;
    Iterator i = jso.keys();
    while (i.hasNext()) {
      String field = (String) i.next();
      Method setMethod = bd.writableProps.get(field);
      if (setMethod != null) {
        try {
          Class param = setMethod.getParameterTypes()[0];
          if (instance instanceof PrimitiveAttribute && "value".equals(field)) {
            log.debug("replace 'value' type for PrimitiveAttribute");
            switch(((PrimitiveAttribute) instance).getType()) {
              case BOOLEAN:
                param = Boolean.class;
                break;
              case DATE:
                param = Date.class;
                break;
              case DOUBLE:
                param = Double.class;
                break;
              case FLOAT:
                param = Float.class;
                break;
              case INTEGER:
                param = Integer.class;
                break;
              case LONG:
                param = Long.class;
                break;
              case SHORT:
                param = Short.class;
                break;
              case CURRENCY:
              case IMGURL:
              case URL:
              case STRING:
                param = String.class;
                break;
              default:
                throw new UnmarshallException("Unknown type of PrimitiveAttribute " +
                    ((PrimitiveAttribute) instance).getType());
            }
          }
          fieldVal = ser.unmarshall(state, param, jso.get(field));
        } catch (UnmarshallException e) {
          throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage());
        }
        log.debug("invoking {}({})", setMethod.getName(), fieldVal);
        invokeArgs[0] = fieldVal;
        try {
          setMethod.invoke(instance, invokeArgs);
        } catch (Throwable e) {
          if (e instanceof InvocationTargetException) {
            e = ((InvocationTargetException) e).getTargetException();
          }
          throw new UnmarshallException("bean " + clazz.getName() + "can't invoke "
              + setMethod.getName() + ": " + e.getMessage());
        }
      }
    }
    return instance;
View Full Code Here

  @SuppressWarnings("unchecked")
  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(Geometry.POINT) || type.equals(Geometry.LINE_STRING) || type.equals(Geometry.POLYGON)
        || type.equals(Geometry.LINEAR_RING) || type.equals(Geometry.MULTI_LINE_STRING) ||
        type.equals(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

  }

  private Geometry createPoint(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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.setCoordinates(new Coordinate[] {coordinate});
    return geometry;
View Full Code Here

  }

  private Geometry createLineString(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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.setCoordinates(coordinates);
    return geometry;
View Full Code Here

  }

  private Geometry createLinearRing(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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"));
    }
    coordinates = checkIfClosed(coordinates);
    geometry.setCoordinates(coordinates);
View Full Code Here

  }

  private Geometry createPolygon(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONObject shell = json.getJSONObject("shell");
    if (shell == null) {
      throw new UnmarshallException("exterior ring is missing");
    }
    int len = 1;
    JSONArray holes = json.getJSONArray("holes");
    if (holes != null) {
      len += holes.length();
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.