Package org.jtester.exception

Examples of org.jtester.exception.JSONException


  private JSONException syntaxError(String message) {
    StringBuffer error = new StringBuffer(message);
    error.append("\n syntax error at position:" + this.index);
    error.append("\n string parsed is:\n");
    error.append(new String(this.input, 0, this.index));
    return new JSONException(error.toString());
  }
View Full Code Here


  protected RuntimeException wrapException(Throwable e) {
    if (e instanceof Exception) {
      return (RuntimeException) e;
    } else {
      return new JSONException(e);
    }
  }
View Full Code Here

    encoder.setFeatures(features);

    try {
      encoder.encode(this.key, writer, references);
    } catch (Exception e) {
      throw new JSONException("encode map key error.", e);
    }
  }
View Full Code Here

    JSONEncoder encoder = JSONEncoder.get(type);
    encoder.setFeatures(features);
    try {
      encoder.encode(this.value, writer, references);
    } catch (Exception e) {
      throw new JSONException("encode map value error.", e);
    }
  }
View Full Code Here

      encoder.setUnMarkClassFlag(true);
    }
    try {
      encoder.encode(value, writer, references);
    } catch (Exception e) {
      throw new JSONException("encode field[" + fieldName + "] error.", e);
    }
  }
View Full Code Here

  public Class getClazzFromJSONFProp(Class defaultClazz) {
    JSONObject object = this.get(JSON_ClazzFlag);
    if (object == null) {
      return defaultClazz;
    } else if (!(object instanceof JSONSingle)) {
      throw new JSONException("the class flag value can only be JSONSingle type.");
    }
    JSONSingle value = (JSONSingle) object;
    String clazzName = value.toClazzName();
    if (StringHelper.isBlankOrNull(clazzName)) {
      this.referenceID = null;
View Full Code Here

  public String getReferFromJSONProp() {
    JSONObject object = (JSONSingle) this.get(JSON_ReferFlag);
    if (object == null) {
      return null;
    } else if (!(object instanceof JSONSingle)) {
      throw new JSONException("the object reference value can only be JSONSingle type.");
    }

    JSONSingle value = (JSONSingle) object;
    String referenceID = value.toStringValue();
    return referenceID;
View Full Code Here

    for (JSONObject key : map.keySet()) {
      if (key == null) {
        continue;
      }
      if (!(key instanceof JSONSingle)) {
        throw new JSONException("illegal syntax, the pojo field name property must be a JSONSingle type.");
      }

      String fieldname = ((JSONSingle) key).toStringValue();
      if (this.isJSONKeyword(fieldname)) {
        continue;
      }
      Field field = this.getFieldByName(fields, fieldname);
      if (field == null) {
        continue;
      }
      try {
        Object value = JSON.toObject(map.get(key), field.getType(), references);
        FieldHelper.setFieldValue(target, field, value);
      } catch (Exception e) {
        throw new JSONException("decode field[" + fieldname + "] error.", e);
      }
    }
  }
View Full Code Here

      return (T) o;
    }

    Class type = map.getClazzFromJSONFProp(this.clazz);
    if (type == null) {
      throw new JSONException("JSONMap must have property that declared the array type.");
    } else if (type.isArray() == false) {
      this.realTargetType = type;
    } else {
      this.realTargetType = type.getComponentType();
    }

    JSONObject array = map.getValueFromJSONProp();
    if (!(array instanceof JSONArray)) {
      throw new JSONException("illegal type for ArrayDecoder. the type can only be JSONArray, but actual is "
          + array.getClass().getName());
    }
    T target = this.newArraysObject(((JSONArray) array).size());
    referenceID = map.getReferenceID();
    if (referenceID != null) {
View Full Code Here

    if (json instanceof JSONSingle) {
      String value = ((JSONSingle) json).toStringValue();
      return (T) value;
    }
    if (!(json instanceof JSONMap)) {
      throw new JSONException("illegal type for JavaBeanDecoder. the json[" + json.toString()
          + "] isn't a JSONMap");
    }
    JSONMap map = (JSONMap) json;
    String referenceID = map.getReferFromJSONProp();
    if (referenceID != null) {
View Full Code Here

TOP

Related Classes of org.jtester.exception.JSONException

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.