Search in sources :

Example 26 with ParserConfig

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

the class TestNonASM method test_no_asm.

public void test_no_asm() throws Exception {
    ParserConfig mapping = new ParserConfig();
    mapping.setAsmEnable(false);
    Assert.assertEquals(false, mapping.isAsmEnable());
    mapping.setAsmEnable(true);
    Assert.assertEquals(true, mapping.isAsmEnable());
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 27 with ParserConfig

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

the class Issue585 method setUp.

protected void setUp() throws Exception {
    ParserConfig.global = new ParserConfig();
    if (!JSON.DEFAULT_TYPE_KEY.equals("mySpace")) {
        JSON.setDefaultTypeKey("mySpace");
    }
    com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Issue585.");
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 28 with ParserConfig

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

the class Issue96 method xx_testCast.

public void xx_testCast() {
    Page<Sub> page = new Page<Sub>(new Sub(1));
    Type type = new TypeReference<Page<Sub>>() {
    }.getType();
    ParserConfig parserconfig = ParserConfig.getGlobalInstance();
    // !!!! this will fail:
    // !!!! com.alibaba.fastjson.JSONException: can not cast to : Page<Sub> TypeUtils.java:719
    Page<Sub> page1 = TypeUtils.cast(page, type, parserconfig);
    System.out.println(page1.sub.getClass());
}
Also used : Type(java.lang.reflect.Type) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 29 with ParserConfig

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

the class NamingSerTest method test_camel.

public void test_camel() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
    Model model = new Model();
    model.personId = 1001;
    String text = JSON.toJSONString(model, config);
    Assert.assertEquals("{\"personId\":1001}", text);
    ParserConfig parserConfig = new ParserConfig();
    parserConfig.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
    Model model2 = JSON.parseObject(text, Model.class, parserConfig);
    Assert.assertEquals(model.personId, model2.personId);
    Model model3 = JSON.parseObject(text, Model.class);
    Assert.assertEquals(model.personId, model3.personId);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 30 with ParserConfig

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

the class NamingSerTest method test_snake.

public void test_snake() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
    Model model = new Model();
    model.personId = 1001;
    String text = JSON.toJSONString(model, config);
    Assert.assertEquals("{\"person_id\":1001}", text);
    ParserConfig parserConfig = new ParserConfig();
    parserConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
    Model model2 = JSON.parseObject(text, Model.class, parserConfig);
    Assert.assertEquals(model.personId, model2.personId);
    Model model3 = JSON.parseObject(text, Model.class);
    Assert.assertEquals(model.personId, model3.personId);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) 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