当前位置: 首页 > 工具软件 > Construct > 使用案例 >

Cannot construct instance of `******` (no Creators, like default construct,exist)

聂鹏云
2023-12-01

问题记录:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; 
nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: 
[simple type, class com.cyj.cloudcommon.utils.api.R]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
Cannot construct instance of `com.cyj.cloudcommon.utils.api.R` (no Creators, like default construct, exist): 
cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (PushbackInputStream); line: 1, column: 2]] with root cause

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
Cannot construct instance of `com.cyj.cloudcommon.utils.api.R` (no Creators, like default construct, exist): 
cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (PushbackInputStream); line: 1, column: 2]

使用jackson对json字符串转对象时报错:
Cannot construct instance of com.cyj.cloudcommon.utils.api.R (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (PushbackInputStream); line: 1, column: 2]

原因分析:

com.cyj.cloudcommon.utils.api.R 代码中自定义了有参数的构造函数,导致默认无参构造函数失效,需要手动添加无参构造函数,用于对象的json序列化。

解决方案:

com.cyj.cloudcommon.utils.api.R 添加默认构造函数

    public R() {
    }
 类似资料: