代码小白,记录自学制作谷粒商城遇到的坑 如有错误请轻喷
情景回顾:
使用postman请求时发现返回的值只会输出定义的Throwable的异常信息,将自定义Throwable注释掉之后发现出现这个警告:
error: Cannot construct instance of `com.weng.shop.product.entity.BrandEntity` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.weng.shop.product.entity.BrandEntity` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 2]]
他说无法从BrandEntity对象值反序列化,这就很离谱了,这都不应该是这个地方出现的异常啊。
怎么会是呢?真令鱼头大。
查询之后,有老哥说原因是在构造类的时候没有写无参构造函数,这不对吧。我明明直接使用了@Data注解啊,就算不使用@AllArgsConstructor 和@NoArgsConstructor注解。至少也应该有一个默认的无参构造器来使用吧。
我再仔细一看,坑爹的来了:
@Data它居然默认生成了一个带Interage的构造器!这是为啥??(我还没研究明白)而且根据我的层层盘查,他是加上了@MIN的注解才会出现这个错误,但是我在网上没找到比较合理的解释?有大佬知道的可以指点一下吗?
只要在BrandEntity中加入一个无参构造函数,一切就正常了。。