JSON parse error: Can not construct instance of io.starter.topic.Topic

后端 未结 2 1714
南笙
南笙 2020-12-29 23:44

Im learning Spring Boot and I made a demo but when I POST a request to add a Object it didn\'t work!

The error message is:

{
    \"timestamp\": 15168         


        
2条回答
  •  别那么骄傲
    2020-12-30 00:45

    For deserialisation purposes Topic must have a zero-arg constructor.

    For example:

    public class Topic {
        private String id;
        private String name;
        private String author;
        private String desc;
    
        // for deserialisation
        public Topic() {}    
    
        public Topic(String id, String name, String author, String desc) {    
            this.id = id;
            this.name = name;
            this.author = author;
            this.desc = desc;
        }
    
        // getters and setters
    
    }     
    

    This is the default behaviour of the Jackson library.

提交回复
热议问题