Search in sources :

Example 11 with ParserConfig

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

the class RefTest12 method test_0.

public void test_0() throws Exception {
    Entity entity = new Entity(123, new Child());
    entity.getChild().setParent(entity);
    String text = JSON.toJSONString(entity);
    System.out.println(text);
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
    Assert.assertEquals(entity2, entity2.getChild().getParent());
    System.out.println(JSON.toJSONString(entity2));
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 12 with ParserConfig

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

the class RefTest14 method test_0.

public void test_0() throws Exception {
    Group admin = new Group("admin");
    User jobs = new User("jobs");
    User sager = new User("sager");
    User sdh5724 = new User("sdh5724");
    admin.getMembers().add(jobs);
    jobs.getGroups().add(admin);
    admin.getMembers().add(sager);
    sager.getGroups().add(admin);
    admin.getMembers().add(sdh5724);
    sdh5724.getGroups().add(admin);
    sager.setReportTo(sdh5724);
    jobs.setReportTo(sdh5724);
    SerializeConfig serializeConfig = new SerializeConfig();
    serializeConfig.setAsmEnable(false);
    String text = JSON.toJSONString(admin, serializeConfig, SerializerFeature.PrettyFormat);
    System.out.println(text);
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    JSON.parseObject(text, Group.class, config, 0);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 13 with ParserConfig

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

the class ParserConfigTest method test_0.

public void test_0() throws Exception {
    ParserConfig config = new ParserConfig();
    config.getDeserializers();
}
Also used : ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 14 with ParserConfig

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

the class WriteClassNameTest_Set2 method test_list.

public void test_list() throws Exception {
    A a = new A();
    Set<B> set = new LinkedHashSet<B>();
    set.add(new B());
    set.add(new B1());
    a.setList(set);
    String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
    System.out.println(text);
    //        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$A\",\"list\":[{},{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$B1\"}]}",
    //                            text);
    ParserConfig parserConfig = new ParserConfig();
    parserConfig.addAccept("com.alibaba.json.bvt");
    A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);
    Assert.assertEquals(2, a1.getList().size());
    Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
    Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 15 with ParserConfig

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

the class FastjsonSCodec method decodeArray.

public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
    ParserConfig config = new ParserConfig();
    DefaultJSONParser parser = new DefaultJSONParser(text, config);
    parser.config(Feature.DisableCircularReferenceDetect, true);
    return parser.parseArray(clazz);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) 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