Search in sources :

Example 6 with ParserConfig

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

the class JSONCreatorTest method test_create_2.

public void test_create_2() throws Exception {
    Entity entity = new Entity(123, "菜姐");
    String text = JSON.toJSONString(entity);
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
    Assert.assertEquals(entity.getId(), entity2.getId());
    Assert.assertEquals(entity.getName(), entity2.getName());
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 7 with ParserConfig

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

the class DenyTest3 method test_0.

public void test_0() throws Exception {
    String text = "{}";
    ParserConfig config = new ParserConfig();
    Properties properties = new Properties();
    properties.put(ParserConfig.DENY_PROPERTY, "com.alibaba.json.bvtVO.deny,,aa");
    config.configFromPropety(properties);
    Exception error = null;
    try {
        JSON.parseObject("{\"@type\":\"com.alibaba.json.bvtVO.deny$A\"}", Object.class, config, JSON.DEFAULT_PARSER_FEATURE);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    JSON.parseObject(text, B.class, config, JSON.DEFAULT_PARSER_FEATURE);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) Properties(java.util.Properties) ParserConfig(com.alibaba.fastjson.parser.ParserConfig) JSONException(com.alibaba.fastjson.JSONException)

Example 8 with ParserConfig

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

the class DenyTest5 method test_c3p0.

public void test_c3p0() throws Exception {
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);
    Object obj = null;
    Exception error = null;
    try {
        obj = JSON.parseObject("{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}", Object.class, config);
        System.out.println(obj.getClass());
    } catch (JSONException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) ParserConfig(com.alibaba.fastjson.parser.ParserConfig) JSONException(com.alibaba.fastjson.JSONException)

Example 9 with ParserConfig

use of com.alibaba.fastjson.parser.ParserConfig 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)

Example 10 with ParserConfig

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

the class BooleanFieldSerializerTest_primitive 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

ParserConfig (com.alibaba.fastjson.parser.ParserConfig)50 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)13 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)10 JSONException (com.alibaba.fastjson.JSONException)7 Properties (java.util.Properties)5 JSONField (com.alibaba.fastjson.annotation.JSONField)2 Feature (com.alibaba.fastjson.parser.Feature)2 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)2 ArrayList (java.util.ArrayList)2 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ResolveTask (com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask)1 JSONLexerBase (com.alibaba.fastjson.parser.JSONLexerBase)1 ParseContext (com.alibaba.fastjson.parser.ParseContext)1 ObjectDeserializer (com.alibaba.fastjson.parser.deserializer.ObjectDeserializer)1 FieldInfo (com.alibaba.fastjson.util.FieldInfo)1 Type (java.lang.reflect.Type)1 LinkedHashSet (java.util.LinkedHashSet)1