解决com.alibaba.fastjson.JSONException: default constructor not found的问题

1.问题描述

在进行JSON和对象互转时,发现有个报错:

com.alibaba.fastjson.JSONException: default constructor not found. class com.hellobike.ph.match.service.taxi.model.message.DelayAddSkuMsg

2.原因和解决方案

通过其提示可以看出在利用fastJson转对象时需要无参的构造函数,而我的对象:

是没有构造函数的,所以需要手动加进去

java 复制代码
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DelayAddSkuMsg {
    /**
     * 订单ID
     */
    private String orderId;

    /**
     * 第几次延迟追加
     */
    private Integer delaySequence;
}

关键就是这个注解:@NoArgsConstructor,在次尝试就会发现已经解决了

相关推荐
Chandler2420 小时前
Go语言:json 作用和语法
开发语言·golang·json
Hfc.1 天前
docker-daemon.json
docker·容器·json
UpUpUp……2 天前
Linux--JsonCpp
linux·运维·服务器·c++·笔记·json
wtsolutions3 天前
Excel-to-JSON插件专业版功能详解:让Excel数据转换更灵活
json·excel·excel-to-json·wtsolutions·专业版
kerryYG3 天前
使用JMETER中的JSON提取器实现接口关联
jmeter·json
柯ran4 天前
JSON|cJSON 介绍以及具体项目编写
c语言·链表·json·github
乐言3615 天前
Jmeter中的Json提取器如何使用?
jmeter·json
北海有初拥5 天前
【从零实现JsonRpc框架#1】Json库介绍
json
GalenWu5 天前
对象转换为 JSON 字符串(或反向解析)
前端·javascript·微信小程序·json
致于数据科学家的小陈5 天前
Go 层级菜单树转 json 处理
python·go·json·菜单树·菜单权限·children