Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastjson(1.2.83)序列化 com.fasterxml.jackson.databind.node.ArrayNode 丢失数据 #4333

Open
xiaomacdut opened this issue Dec 28, 2022 · 2 comments

Comments

@xiaomacdut
Copy link

ArrayNode arrayNode=new ArrayNode(new JsonNodeFactory(true)); arrayNode.add(32342342342l);
我们的数据类型是ArrayNode,序列化上面的arrayNode的结果是:
{"@type":"com.fasterxml.jackson.databind.node.ArrayNode","array":true,"bigDecimal":false,"bigInteger":false,"binary":false,"boolean":false,"containerNode":true,"double":false,"empty":false,"float":false,"floatingPointNumber":false,"int":false,"integralNumber":false,"long":false,"missingNode":false,"nodeType":"ARRAY","null":false,"number":false,"object":false,"pojo":false,"short":false,"textual":false,"valueNode":false}

32342342342l这个值丢失了

@wenshao
Copy link
Member

wenshao commented Jan 28, 2023

https://github.com/alibaba/fastjson2/issues
可以提issue到这里么?

@justToBeGood
Copy link

debug版本:1.2.83
JSON.toJSONString(Object object)进行对象序列化会调用object对应的ObjectSerializer接口实现类的write(),而com.fasterxml.jackson.databind.node.ArrayNode对应的ObjectSerializer实现类是com.alibaba.fastjson.serializer.JavaBeanSerializer,获取的位置com.alibaba.fastjson.serializer.JSONSerializer#getObjectWriter

深入到getObjectWriter(),经过一系列的判断,选择创建JavaBeanSerializer,位置:/com/alibaba/fastjson/serializer/SerializeConfig.java:821,可以看到是基于BeanInfo数据进行创建的,BeanInfo包含了要序列化的数据
image
而在TypeUtils.buildBeanInfo中重点就是这个,根据is和get开头的函数来确定Field,ArrayNode.add()是将对象放到_children,该Field并没有get方法
image
在JavaBeanSerializer.write()就是根据BeanInfo的数据来序列化信息了
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants