Exemple #1
0
 @SuppressWarnings("unchecked")
 public static final <T> T parseObject(
     String input, Type clazz, ParseProcess processor, Feature... features) {
   return (T)
       parseObject(
           input, clazz, ParserConfig.getGlobalInstance(), DEFAULT_PARSER_FEATURE, features);
 }
Exemple #2
0
  public static final JSONArray parseArray(String text) {
    if (text == null) {
      return null;
    }

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());

    JSONArray array;

    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
      lexer.nextToken();
      array = null;
    } else if (lexer.token() == JSONToken.EOF) {
      array = null;
    } else {
      array = new JSONArray();
      parser.parseArray(array);

      parser.handleResovleTask(array);
    }

    parser.close();

    return array;
  }
Exemple #3
0
 @SuppressWarnings("unchecked")
 public static final <T> T parseObject(String text, TypeReference<T> type, Feature... features) {
   return (T)
       parseObject(
           text,
           type.getType(),
           ParserConfig.getGlobalInstance(),
           DEFAULT_PARSER_FEATURE,
           features);
 }
Exemple #4
0
  public static final Object parse(String text, int features) {
    if (text == null) {
      return null;
    }

    DefaultJSONParser parser =
        new DefaultJSONParser(text, ParserConfig.getGlobalInstance(), features);
    Object value = parser.parse();

    parser.handleResovleTask(value);

    parser.close();

    return value;
  }
Exemple #5
0
  public static final List<Object> parseArray(String text, Type[] types) {
    if (text == null) {
      return null;
    }

    List<Object> list;

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    Object[] objectArray = parser.parseArray(types);
    if (objectArray == null) {
      list = null;
    } else {
      list = Arrays.asList(objectArray);
    }

    parser.handleResovleTask(list);

    parser.close();

    return list;
  }
Exemple #6
0
  @SuppressWarnings("unchecked")
  public static final <T> T parseObject(char[] input, int length, Type clazz, Feature... features) {
    if (input == null || input.length == 0) {
      return null;
    }

    int featureValues = DEFAULT_PARSER_FEATURE;
    for (Feature featrue : features) {
      featureValues = Feature.config(featureValues, featrue, true);
    }

    DefaultJSONParser parser =
        new DefaultJSONParser(input, length, ParserConfig.getGlobalInstance(), featureValues);
    T value = (T) parser.parseObject(clazz);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
  }
Exemple #7
0
  @SuppressWarnings("unchecked")
  public static final <T> T parseObject(
      String input, Type clazz, int featureValues, Feature... features) {
    if (input == null) {
      return null;
    }

    for (Feature featrue : features) {
      featureValues = Feature.config(featureValues, featrue, true);
    }

    DefaultJSONParser parser =
        new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
    T value = (T) parser.parseObject(clazz);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
  }
Exemple #8
0
  public static final <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
      return null;
    }

    List<T> list;

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
      lexer.nextToken();
      list = null;
    } else {
      list = new ArrayList<T>();
      parser.parseArray(clazz, list);

      parser.handleResovleTask(list);
    }

    parser.close();

    return list;
  }
Exemple #9
0
  public static final Object parse(
      byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
    charsetDecoder.reset();

    int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
    char[] chars = ThreadLocalCache.getChars(scaleLength);

    ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
    CharBuffer charBuf = CharBuffer.wrap(chars);
    IOUtils.decode(charsetDecoder, byteBuf, charBuf);

    int position = charBuf.position();

    DefaultJSONParser parser =
        new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
    Object value = parser.parse();

    parser.handleResovleTask(value);

    parser.close();

    return value;
  }
Exemple #10
0
 public static final <T> T toJavaObject(JSON json, Class<T> clazz) {
   return TypeUtils.cast(json, clazz, ParserConfig.getGlobalInstance());
 }
Exemple #11
0
 // ///////
 public static final Object toJSON(Object javaObject) {
   return toJSON(javaObject, ParserConfig.getGlobalInstance());
 }
Exemple #12
0
 @SuppressWarnings("unchecked")
 public static final <T> T parseObject(String text, Class<T> clazz, Feature... features) {
   return (T)
       parseObject(
           text, (Type) clazz, ParserConfig.getGlobalInstance(), DEFAULT_PARSER_FEATURE, features);
 }