Search in sources :

Example 1 with ParserConfig

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

the class ListFieldTest method test_codec_null.

public void test_codec_null() throws Exception {
    V0 v = new V0();
    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);
    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"value\":null}", text);
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);
    config.setAsmEnable(false);
    V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);
    Assert.assertEquals(v1.getValue(), v.getValue());
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 2 with ParserConfig

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

the class Bug_102_for_rongganlin method test_bug.

public void test_bug() throws Exception {
    TestBean testProcessInfo = new TestBean();
    com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
    jo.put("id", 121);
    ParserConfig config = new ParserConfig();
    testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 3 with ParserConfig

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

the class StringFieldTest method test_codec_null.

public void test_codec_null() throws Exception {
    V0 v = new V0();
    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);
    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"value\":null}", text);
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);
    Assert.assertEquals(v1.getValue(), v.getValue());
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 4 with ParserConfig

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

the class DefaultExtJSONParserTest_3 method test_7.

public void test_7() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("123");
    ParserConfig mapping = new ParserConfig();
    parser.setConfig(mapping);
    Assert.assertEquals(mapping, parser.getConfig());
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 5 with ParserConfig

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

the class JSONCreatorFactoryTest 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)

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