Search in sources :

Example 36 with ParserConfig

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

the class JSONCreatorTest_double_obj method test_create_2.

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

Example 37 with ParserConfig

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

the class JSONCreatorTest_float method test_create_2.

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

Example 38 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 39 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 40 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)

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