Java Code Examples for com.alibaba.fastjson.parser.DefaultJSONParser#handleResovleTask()

The following examples show how to use com.alibaba.fastjson.parser.DefaultJSONParser#handleResovleTask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReflectUtil.java    From game-server with MIT License 6 votes vote down vote up
/**
 * wzy扩展
 *
 * @param input
 * @param value
 * @param config
 * @param processor
 * @param featureValues
 * @param features
 */
private static void reflectObject(String input, Object value, ParserConfig config, ParseProcess processor,
		int featureValues, Feature... features) {
	if (input == null) {
		return;
	}
	for (Feature featrue : features) {
		featureValues = Feature.config(featureValues, featrue, true);
	}

	DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);

	if (processor instanceof ExtraTypeProvider) {
		parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
	}

	if (processor instanceof ExtraProcessor) {
		parser.getExtraProcessors().add((ExtraProcessor) processor);
	}
	parser.parseObject(value);
	parser.handleResovleTask(value);
	parser.close();
}
 
Example 2
Source File: JSON.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

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

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

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
 
Example 3
Source File: JSON.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <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 feature : features) {
        featureValues = Feature.config(featureValues, feature, true);
    }

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

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
 
Example 4
Source File: JSON.java    From uavstack with Apache License 2.0 6 votes vote down vote up
public static JSONArray parseArray(String text) {
    if (text == null) {
        return null;
    }

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

    JSONArray array;

    JSONLexer lexer = parser.lexer;
    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;
}
 
Example 5
Source File: JSON.java    From uavstack with Apache License 2.0 6 votes vote down vote up
public static <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.lexer;
    int token = lexer.token();
    if (token == JSONToken.NULL) {
        lexer.nextToken();
        list = null;
    } else if (token == JSONToken.EOF && lexer.isBlankInput()) {
        list = null;
    } else {
        list = new ArrayList<T>();
        parser.parseArray(clazz, list);

        parser.handleResovleTask(list);
    }

    parser.close();

    return list;
}
 
Example 6
Source File: JSON.java    From uavstack with Apache License 2.0 6 votes vote down vote up
public static 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;
}
 
Example 7
Source File: JSON.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @since 1.2.38
 */
public static Object parse(String text, ParserConfig config, int features) {
    if (text == null) {
        return null;
    }

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

    parser.handleResovleTask(value);

    parser.close();

    return value;
}
 
Example 8
Source File: JSON.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
                                      int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

    if (features != null) {
        for (Feature feature : features) {
            featureValues |= feature.mask;
        }
    }

    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);

    if (processor != null) {
        if (processor instanceof ExtraTypeProvider) {
            parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
        }

        if (processor instanceof ExtraProcessor) {
            parser.getExtraProcessors().add((ExtraProcessor) processor);
        }

        if (processor instanceof FieldTypeResolver) {
            parser.setFieldTypeResolver((FieldTypeResolver) processor);
        }
    }

    T value = (T) parser.parseObject(clazz, null);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
 
Example 9
Source File: FastjsonHttpMessageConverter.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
		throws IOException, HttpMessageNotReadableException {
	String json = IOUtils.toString(inputMessage.getBody(), getCharset(inputMessage.getHeaders()));
	DefaultJSONParser parser = new DefaultJSONParser(json, this.parserConfig);
	Object value = parser.parseObject(type);

	parser.handleResovleTask(value);

	parser.close();

	return value;
}
 
Example 10
Source File: JSON.java    From uavstack with Apache License 2.0 4 votes vote down vote up
public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
    charsetDecoder.reset();

    int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
    char[] chars = allocateChars(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;
}
 
Example 11
Source File: JSON.java    From uavstack with Apache License 2.0 4 votes vote down vote up
public static <T> void handleResovleTask(DefaultJSONParser parser, T value) {
    parser.handleResovleTask(value);
}