jackson反序列化,成员变量是list,无法解析泛型?

新手上路,请多包涵

问题描述

jackson反序列化,成员变量是List,无法解析泛型
使用ObjectMapper.readValue无法正确解析出对象中List变量的泛型;但在Spring Controller中是正确的,想要了解spring是如何做到的

相关代码

javabean如下:

@ApiModel
@Data
public class ApplyRefundItemIBay {


    @ApiModelProperty(value = "门诊流水号", required = true)
    @NotBlank(message = "门诊流水号不得为空")
    private String clinic_no;

    @ApiModelProperty(value = "患者ID", required = true)
    @NotBlank(message = "患者ID不得为空")
    private String patient_id;

    @ApiModelProperty(value = "患者姓名", required = false)
    private String patient_name;

    @ApiModelProperty(value = "申请退费人编号", required = true)
    @NotBlank(message = "申请退费人编号不得为空")
    private String apply_refund_per_id;

    @ApiModelProperty(value = "申请退费人姓名", required = true)
    @NotBlank(message = "申请退费人姓名不得为空")
    private String apply_refund_per_name;

    @ApiModelProperty(value = "申请退费科室编号", required = true)
    @NotBlank(message = "申请退费科室编号不得为空")
    private String apply_refund_dep_id;

    @ApiModelProperty(value = "申请退费科室名称", required = false)
    private String apply_refund_dep_name;

    @ApiModelProperty(value = "申请退费项目列表",required = true)
    @NotNull(message = "申请退费项目列表不允许为空")
    @Size(min = 1,max =1000 )
    @Valid
    public List<ApplyRefundItemListPan> applyRefundItemListPans ;

}

json参数如下:

{
  "applyRefundItemListPans": [
    {
      "advice_details_no": "",
      "advice_item_code": "",
      "advice_item_name": "",
      "advice_no": "",
      "audit_code": "",
      "bill_code": "",
      "drug_spec": "",
      "fee_item_no": "",
      "fee_no": "",
      "hosp_area_id": "",
      "hosp_id": "",
      "insurance_code": "",
      "insurance_name": "",
      "item_code": "",
      "item_name": "",
      "item_type": "",
      "price": 0,
      "quantity": 0,
      "repetition": 0,
      "return_amount": 0,
      "specs_code": "",
      "total_amount": 0,
      "unit": ""
    }
  ],
  "apply_refund_dep_id": "",
  "apply_refund_dep_name": "",
  "apply_refund_per_id": "",
  "apply_refund_per_name": "",
  "clinic_no": "",
  "patient_id": "",
  "patient_name": ""
}

其中applyRefundItemListPans变量为List类型,请问这种作为成员变量的泛型,无法使用JavaType或者TypeReference,如何解析?SpringMVC又是通过什么机制做到解析的?时间着急在SpringMVC源码中一时找不到答案

阅读 2.6k
3 个回答

你这里没有泛型

新手上路,请多包涵

代码方便列一下,我本地可以解析List里的内容
image.png

很遗憾,你一开始就把springmvc的实现方式淘汰了,他就是用的javaType,使用javaType或者是TypeReference,一般是类上有泛型,你这类上面没有泛型,直接readValue就能搞定

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题