首页 > 解决方案 > 无法从 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 是可序列化的问题存在一些问题。也许它需要别的东西。

标签: javaserializable

解决方案


推荐阅读