Jackson Deserialization: unrecognized field

后端 未结 3 1313
说谎
说谎 2021-01-25 02:36

From the tutorial I had the impression that this should work (simplified example):

public class Foo {
    private String bar;
    public String getBar() {
              


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-25 03:24

    The Foo class needs an instance property of type Qux for automatic deserialization to work. The way the Foo class is currently defined, there is no destination property to inject the qux JSON object values.

    public class Foo {
       private String bar;
    
       public String getBar() {
           return bar;
       }
    
       public void setBar(String bar) {
           this.bar = bar;
       }
    
       // additional property 
       private Qux qux;
    
       public Qux getQux() {
           return qux;
       }
    
       public void setQux(Qux value) {
           qux = value;
       }
    
       public static class Qux {
           private String foobar;
    
           public String getFoobar() {
             return foobar;
           }
    
           public void setFoobar(String foobar) {
               this.foobar = foobar;
           }
        }
    }
    

提交回复
热议问题