记录多态如何序列化与反序列化
前言:最近在公司项目中遇到了多态序列化异常的问题,具体详情如下:
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.x.x.x.Payment]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.x.x.x.Payment` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
项目中需要用户添加自己的收款方式,而收款方式又分为ABC三种,
继承了Payment这个类,接口代码如下:
//隐去了请求url和类型
@ApiOperation("添加收款方式")
public ResultInfo<? extends Payment