jackson IOException: Can not deserialize Class com.mycompany.models.Person$Address (of type non-static member class) as a Bean

后端 未结 2 1979
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 10:26

I have a class that looks like this:

public class Person {
    public class Address {
        private String line1;
        private String line2;
        private         


        
2条回答
  •  不知归路
    2021-02-19 11:22

    Because inner classes do not have a default zero argument constructor (they have a hidden reference to the outer/parent class) Jackson cannot instantiate them.

    The solution is to use static inner classes:

    public class Outer {
        static class Inner {
            private String foo;
            public String getFoo() { return foo; }
        }
    }
    

    Original Answer:

    There are some issues in implementation and it seems like you can't serialize such classes, see cowtowncoder for details.

提交回复
热议问题