Search in sources :

Example 41 with ParserConfig

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

the class DenyTest method test_0.

public void test_0() throws Exception {
    String text = "{}";
    ParserConfig config = new ParserConfig();
    config.addDeny(null);
    config.addDeny("com.alibaba.json.bvtVO.deny");
    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) ParserConfig(com.alibaba.fastjson.parser.ParserConfig) JSONException(com.alibaba.fastjson.JSONException)

Example 42 with ParserConfig

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

the class DenyTest9 method test_autoTypeDeny.

public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();
    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());
    Properties properties = new Properties();
    properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
    properties.put(ParserConfig.AUTOTYPE_ACCEPT, "com.alibaba.json.bvt.parser.deser.deny.DenyTest9");
    // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9
    config.configFromPropety(properties);
    assertFalse(config.isAutoTypeSupport());
    Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest9$Model\"}", Object.class, config);
    assertEquals(Model.class, obj.getClass());
}
Also used : Properties(java.util.Properties) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 43 with ParserConfig

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

the class DenyTest2 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");
    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 44 with ParserConfig

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

the class DenyTest6 method test_autoTypeDeny.

public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();
    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());
    config.addDeny("com.alibaba.json.bvt.parser.deser.deny.DenyTest6");
    config.setAutoTypeSupport(false);
    Exception error = null;
    try {
        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest6$Model\"}", 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 45 with ParserConfig

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

the class DenyTest7 method test_autoTypeDeny.

public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();
    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());
    Properties properties = new Properties();
    properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
    config.configFromPropety(properties);
    assertFalse(config.isAutoTypeSupport());
    Exception error = null;
    try {
        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest7$Model\"}", Object.class, config);
        System.out.println(obj.getClass());
    } catch (JSONException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) Properties(java.util.Properties) ParserConfig(com.alibaba.fastjson.parser.ParserConfig) JSONException(com.alibaba.fastjson.JSONException)

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