使用Jackson, SpringBoot自定义反序列化列表-不工作



我试图使列表的自定义反序列化。我在网上找到了一些建议,但都没能奏效。

Car.class

public class Car {
private String market;
private String date;
@JsonDeserialize(using = CustomDeserializer.class)
private List<CarValue> cars;

CustomDeserializer.java

public class CustomDeserializer extends JsonDeserializer<List<CarValue>> {
@Override
public List<CarValue> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = p.getCodec().readTree(p);
List<CarValue> result = new ArrayList<CarValue>();
for(JsonNode value : node) {
//result.add(node.get("name"));
}
return result;
}
}

我不确定如何从我的CustomDeserializer类返回想要的数据。

List<QuoteValue>我只想返回键为name的数据。

我该怎么做呢?

我有一个例子。

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import java.util.List;
public class VoucherPartnerGiftCardOp {
@Expose
private int voucherPartnerGiftCardID;
@Expose
private int marchantID;

public VoucherPartnerGiftCardOp() {
}
public int getVoucherPartnerGiftCardID() {
return voucherPartnerGiftCardID;
}
public void setVoucherPartnerGiftCardID(int voucherPartnerGiftCardID) {
this.voucherPartnerGiftCardID = voucherPartnerGiftCardID;
}
public int getMarchantID() {
return marchantID;
}
....
public String toJson() {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
return gson.toJson(this);
}
}