java - 无法从 START_OBJECT 令牌中反序列化 `` 的实例
问题描述
我正在尝试将 json 发送到队列,但我面临与将可序列化对象转换为 josn 字符串相关的问题。
我有以下代码:
ListReturnTaxLiqdc listReturnTaxLiqdc = new ListReturnTaxLiqdc((List<TaxLiqdcDTO>) taxLiqdcs);
String json = listReturnTaxLiqdc.toJson(objectMapper);
jmsTemplate.send(QRM_TAX_LIQDC, messageCreator -> {
Message message = jmsTemplate.getMessageConverter().toMessage(json, messageCreator);
return message;
});
我的 ListReturnTaxLiqdc:
public class ListReturnTaxLiqdc {
private List<TaxLiqdcDTO> taxLiqdcDTOList;
public ListReturnTaxLiqdc(List<TaxLiqdcDTO> taxLiqdcDTOList) {
this.taxLiqdcDTOList = taxLiqdcDTOList;
}
public List<TaxLiqdcDTO> getTaxLiqdcDTOList() {
return taxLiqdcDTOList;
}
public void setTaxLiqdcDTOList(List<TaxLiqdcDTO> taxLiqdcDTOList) {
this.taxLiqdcDTOList = taxLiqdcDTOList;
}
String toJson(ObjectMapper mapper) throws JsonProcessingException {
return mapper.writeValueAsString(this);
}
}
我的 TaxLiqdcDTO:
public class TaxLiqdcDTO extends TaxLiqdcEvent {
private static final long serialVersionUID = 1L;
@Getter
private String type = "taxLiqdcWithdraw";
...
我的 TaxLiqdc 事件:
public abstract class TaxLiqdcEvent implements Serializable {
public abstract void onMessage() throws InvalidMessageException, Exception;
}
消息错误:
Cannot deserialize instance of `[TaxLiqdcEvent;` out of START_OBJECT token
at [Source: (String)"{"taxLiqdcDTOList":[{"type":"taxLiqdcWithdraw","type":"taxLiqdcWithdraw","idDeposit":1,"idTransaction":3,"numAgency":1,"numAccount":201413,"referenceDate":"2013-05-06","irValue":0.66,"iofValue":0},{"type":"taxLiqdcWithdraw","type":"taxLiqdcWithdraw","idDeposit":2,"idTransaction":4,"numAgency":1,"numAccount":201413,"referenceDate":"2013-05-06","irValue":0.66,"iofValue":0}]}"; line: 1, column: 1]
我认为对象 TaxLiqdcEvent 是可序列化的问题存在一些问题。也许它需要别的东西。
解决方案
推荐阅读
- angularjs - ANGULAR JS:向一个 Angular 模块添加多个工厂和指令
- android - HiltWorkerFactory:在 AppStartup 中配置 WorkManagerInitializer
- python - Telethon:对 Telegram 的自动回复停止工作。怎么修?
- opencl - 如何在矢量处理器 SIMD 上的 opencl 中添加矢量(int16)的所有元素?
- c# - 如何使用 System.IO.Pipelines 包创建响应 TCP 侦听器?
- sql - postgresql 中没有 uuid 过滤器
- excel - 如何遍历工作簿VBA中的所有工作表
- ios - SQLite.swift 是否有能力检测和通知表数据变化?
- c++ - 我不能用函数在字符串中加倍字符
- three.js - Mapbox GL JS + 自定义 3D 图层(three.js):闪烁消失