简体   繁体   English

反序列化复杂的json对象+ Spring Boot

[英]Deserialize a complex json object + Spring boot

I have a class as below 我有一个如下课程

public class Entity {

    @Id
    private String id;
    private String name;
    private List<Person> Persons;

and I have a simple Rest request as: 我有一个简单的Rest请求,如:

@RequestMapping(value = "/create", method = RequestMethod.POST)
    public ResponseEntity<?> createEntity(@RequestBody Entity entity) 

There is a problem when I want to deserialize this object: 我想反序列化此对象时出现问题:

Could not read JSON document: Can not construct instance of com.example.demo.dto.Person: no String-argument constructor/factory method to deserialize from. 无法读取JSON文档:无法构造com.example.demo.dto.Person的实例:没有要反序列化的String-argument构造函数/工厂方法。

The main idea that I dont want use static inner class. 我不想使用的主要思想是静态内部类。

  1. Create a Person class (preferably a high level class rather than an inner class) 创建一个Person类(最好是高级类,而不是内部类)
  2. either don't add any constructers or add default constructer. 要么不添加任何构造函数,要么添加默认构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM