Fastjson 转字符串报错的问题: write javaBean error, fastjson version 1.2.71, class xxx...., fieldName : 0

分享知识 传递快乐

在使用 fastjson 打印请求报文时,突然出现提示错误:

write javaBean error, fastjson version 1.2.71, class xxx...., fieldName : 0。

问题分析:

请求报文:

[{
	"receiptAmount": 0.0,
	"poStatus": 2,
	"customItem204__c": 1,
	"po": "O20211118-0020",
	"operate": "update",
	"paymentPercent": 0.0,
	"balance": 0.0,
	"customItem214__c": 1,
	"customItem226__c": "[{\"fileId\":2006083573301958,\"fileName\":\"56829a66-5b4e-40a8-a4b7-4bf47a6f1acc.png\",\"name\":\"56829a66-5b4e-40a8-a4b7-4bf47a6f1acc.png\",\"fileLength\":5182,\"size\":5182,\"fileUrl\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"url\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"filePixels\":{\"small\":{\"width\":258,\"height\":206},\"large\":{\"width\":258,\"height\":206},\"origin\":{\"width\":258,\"height\":206}},\"pic\":\"258*206\",\"lpic\":\"258*206\",\"fileLUrl\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/l_8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"lurl\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/l_8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"fileSUrl\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/s_8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"surl\":\"https://crmtencentprod-1253467224.cos.ap-guangzhou.myqcloud.com/636738865791652/2021/11/18/s_8c77b789-1a32-4ce5-8482-fc69663fcff8.png\",\"type\":1}]",
	"payments": 0.0,
	"lockStatus": 1,
	"updatedBy": 1839350438101707,
	"customItem166__c": 1658305003061909,
	"applicantId": 1839350438101707,
	"customItem174__c": 0.0,
	"overdueStatus": 2,
	"initAmount": 0.0,
	"approvalStatus": 3,
	"actualInvoicedAmount": 0.0,
	"comment": "111",
	"contractId": 1731633919640292,
	"dimDepart": 655543879385770,
	"receiptBalance": 0.0,
	"customItem196__c": 0.0,
	"customItem209__c": 2,
	"surplusPayable": 0.0,
	"priceId": 640151491068629,
	"updatedAt": 1637207142877,
	"customItem220__c": 0.0,
	"totalAdditionalDiscountAmount": 0.0,
	"apiKey": "order",
	"accountId": 753630970987206,
	"customItem225__c": 2,
	"customItem173__c": 1.0,
	"customItem219__c": 5,
	"paymentStatus": 1,
	"totalDiscountAmount": 0.0,
	"customItem206__c": 2,
	"lineItemCount": 1,
	"ownerId": 1839350438101707,
	"id": 2006083639362213,
	"roStatus": 1,
	"customerAccount__c": "100016961262",
	"customItem222__c": 0.0,
	"listTotal": 0.0,
	"amountUnbilled": 0.0,
	"totalPaymentAmount": 0.0,
	"effectiveDate": 1637206472634,
	"entityType": 636789772255911,
	"belongId": 35,
	"totalInvoiceAdjustmentAmount": 0.0,
	"customItem216__c": "十大科技是",
	"customItem190__c": 1,
	"customItem194__c": 1,
	"paidAmount": 0.0,
	"totalRefundAmount": 0.0,
	"transactionDate": 1637206320000,
	"createdAt": 1637206440128,
	"customItem228__c": 2,
	"orderVersion": 1,
	"amountInvoiced": 0.0,
	"productsAmount": 1.0,
	"customItem191__c": 1,
	"totalSystemDiscountAmount": 0.0,
	"invoiceBalance": 0.0,
	"createdBy": 1839350438101707,
	"amount": 0.0,
	"paymentBalance": 0.0,
	"customItem229__c": "AC-YW-20210508-0001",
	"customItem192__c": 1,
	"paymentAmountPlanned": 0.0,
	"customItem215__c": 2
}]

经排查发现,报错的原因是因为报文中的 customItem226__c 字段的内容在 fastjson 序列化对象时报错导致。

解决序列化为题如下:

1、在字段上添加注解 @JSONField(serialize =false), 这样做不会报错可以顺利打印,但是添加该注解的字段将不会被序列化并放入到json字符串中

2、在 toJSONString 调用过程中加入 SerializerFeature.IgnoreErrorGetter (推荐)

例如:JSON.toJSONString(requestErrorInfo, SerializerFeature.IgnoreErrorGetter))

—————————
如有不足请留言指正
相互学习,共同进步 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旷野历程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值