Search in sources :

Example 1 with Feature

use of com.alibaba.fastjson.parser.Feature in project fastjson by alibaba.

the class JSON method parseObject.

@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;
}
Also used : FieldTypeResolver(com.alibaba.fastjson.parser.deserializer.FieldTypeResolver) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) ExtraTypeProvider(com.alibaba.fastjson.parser.deserializer.ExtraTypeProvider) ExtraProcessor(com.alibaba.fastjson.parser.deserializer.ExtraProcessor) SerializerFeature(com.alibaba.fastjson.serializer.SerializerFeature) Feature(com.alibaba.fastjson.parser.Feature)

Example 2 with Feature

use of com.alibaba.fastjson.parser.Feature in project uavstack by uavorg.

the class JSON method parseObject.

@SuppressWarnings("unchecked")
public static final <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor, int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }
    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);
    }
    T value = (T) parser.parseObject(clazz);
    parser.handleResovleTask(value);
    parser.close();
    return (T) value;
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) ExtraTypeProvider(com.alibaba.fastjson.parser.deserializer.ExtraTypeProvider) ExtraProcessor(com.alibaba.fastjson.parser.deserializer.ExtraProcessor) SerializerFeature(com.alibaba.fastjson.serializer.SerializerFeature) Feature(com.alibaba.fastjson.parser.Feature)

Example 3 with Feature

use of com.alibaba.fastjson.parser.Feature in project uavstack by uavorg.

the class JSON method parseObject.

@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;
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) SerializerFeature(com.alibaba.fastjson.serializer.SerializerFeature) Feature(com.alibaba.fastjson.parser.Feature)

Example 4 with Feature

use of com.alibaba.fastjson.parser.Feature in project fastjson by alibaba.

the class ArrayListStringDeserializerTest method parseObject.

public static final <T> T parseObject(String input, Type clazz, Feature... features) {
    if (input == null) {
        return null;
    }
    int featureValues = 0;
    for (Feature feature : features) {
        featureValues = Feature.config(featureValues, feature, true);
    }
    DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
    T value = (T) parser.parseObject(clazz);
    if (clazz != JSONArray.class) {
        parser.close();
    }
    return (T) value;
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) Feature(com.alibaba.fastjson.parser.Feature)

Example 5 with Feature

use of com.alibaba.fastjson.parser.Feature in project fastjson by alibaba.

the class BooleanFieldSerializerTest method parseObjectNoAsm.

@SuppressWarnings("unchecked")
public static final <T> T parseObjectNoAsm(String input, Type clazz, int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }
    for (Feature feature : features) {
        featureValues = Feature.config(featureValues, feature, true);
    }
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);
    T value = (T) parser.parseObject(clazz);
    if (clazz != JSONArray.class) {
        parser.close();
    }
    return (T) value;
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) SerializerFeature(com.alibaba.fastjson.serializer.SerializerFeature) Feature(com.alibaba.fastjson.parser.Feature) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Aggregations

DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)9 Feature (com.alibaba.fastjson.parser.Feature)9 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)8 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)2 ExtraProcessor (com.alibaba.fastjson.parser.deserializer.ExtraProcessor)2 ExtraTypeProvider (com.alibaba.fastjson.parser.deserializer.ExtraTypeProvider)2 FieldTypeResolver (com.alibaba.fastjson.parser.deserializer.FieldTypeResolver)1