问题描述
我正在尝试将 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";
...
我的 TaxLiqdcEvent:
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","idDeposit":2,"idTransaction":4,"iofValue":0}]}"; line: 1,column: 1]
我认为对象TaxLiqdcEvent is Serializable 的问题存在一些问题。也许它需要别的东西。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)