Search in sources :

Example 6 with FieldDeserializer

use of com.alibaba.fastjson.parser.deserializer.FieldDeserializer in project fastjson by alibaba.

the class JSONFieldTest_0 method test_0.

public void test_0() throws Exception {
    VO vo = new VO();
    vo.setF0(100);
    vo.setF1(101);
    vo.setF2(102);
    String text = JSON.toJSONString(vo);
    System.out.println(text);
    Assert.assertEquals("{\"f2\":102,\"f1\":101,\"f0\":100}", text);
    VO vo_decoded = JSON.parseObject(text, VO.class);
    Assert.assertEquals(vo.f0, vo_decoded.f0);
    Assert.assertEquals(vo.f1, vo_decoded.f1);
    Assert.assertEquals(vo.f2, vo_decoded.f2);
    JavaBeanDeserializer javaBeanDeser = null;
    ObjectDeserializer deser = ParserConfig.getGlobalInstance().getDeserializer(VO.class);
    javaBeanDeser = (JavaBeanDeserializer) deser;
    Field field = JavaBeanDeserializer.class.getDeclaredField("sortedFieldDeserializers");
    field.setAccessible(true);
    FieldDeserializer[] fieldDeserList = (FieldDeserializer[]) field.get(javaBeanDeser);
    Assert.assertEquals(3, fieldDeserList.length);
    Assert.assertEquals("f2", fieldDeserList[0].fieldInfo.name);
    Assert.assertEquals("f1", fieldDeserList[1].fieldInfo.name);
    Assert.assertEquals("f0", fieldDeserList[2].fieldInfo.name);
}
Also used : FieldDeserializer(com.alibaba.fastjson.parser.deserializer.FieldDeserializer) JSONField(com.alibaba.fastjson.annotation.JSONField) Field(java.lang.reflect.Field) ObjectDeserializer(com.alibaba.fastjson.parser.deserializer.ObjectDeserializer) JavaBeanDeserializer(com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer)

Example 7 with FieldDeserializer

use of com.alibaba.fastjson.parser.deserializer.FieldDeserializer in project fastjson by alibaba.

the class JSONFieldTest_1 method test_0.

public void test_0() throws Exception {
    VO vo = new VO();
    vo.setF0(100);
    vo.setF1(101);
    vo.setF2(102);
    String text = JSON.toJSONString(vo);
    System.out.println(text);
    Assert.assertEquals("{\"f2\":102,\"f1\":101,\"f0\":100}", text);
    VO vo_decoded = JSON.parseObject(text, VO.class);
    Assert.assertEquals(vo.f0, vo_decoded.f0);
    Assert.assertEquals(vo.f1, vo_decoded.f1);
    Assert.assertEquals(vo.f2, vo_decoded.f2);
    JavaBeanDeserializer javaBeanDeser = null;
    ObjectDeserializer deser = ParserConfig.getGlobalInstance().getDeserializer(VO.class);
    javaBeanDeser = (JavaBeanDeserializer) deser;
    Field field = JavaBeanDeserializer.class.getDeclaredField("sortedFieldDeserializers");
    field.setAccessible(true);
    FieldDeserializer[] fieldDeserList = (FieldDeserializer[]) field.get(javaBeanDeser);
    Assert.assertEquals(3, fieldDeserList.length);
    Assert.assertEquals("f2", fieldDeserList[0].fieldInfo.name);
    Assert.assertEquals("f1", fieldDeserList[1].fieldInfo.name);
    Assert.assertEquals("f0", fieldDeserList[2].fieldInfo.name);
}
Also used : FieldDeserializer(com.alibaba.fastjson.parser.deserializer.FieldDeserializer) JSONField(com.alibaba.fastjson.annotation.JSONField) Field(java.lang.reflect.Field) ObjectDeserializer(com.alibaba.fastjson.parser.deserializer.ObjectDeserializer) JavaBeanDeserializer(com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer)

Aggregations

FieldDeserializer (com.alibaba.fastjson.parser.deserializer.FieldDeserializer)7 JavaBeanDeserializer (com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer)6 ObjectDeserializer (com.alibaba.fastjson.parser.deserializer.ObjectDeserializer)5 JSONField (com.alibaba.fastjson.annotation.JSONField)2 ResolveFieldDeserializer (com.alibaba.fastjson.parser.deserializer.ResolveFieldDeserializer)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 WildcardType (java.lang.reflect.WildcardType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1