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

后端 未结 2 1991
没有蜡笔的小新
没有蜡笔的小新 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:19

    Correct, this used to be something you can not do with current Jackson versions (1.8 and earlier). But is it absolutely necessary for inner class to be non-static? If not, just add 'static' in declaration of Address and it'll work fine; problem is with the "hidden" this-pointer that non-static inner classes take via constructor.

    Jackson 1.9 will actually supports deserialization of simple uses of non-static inner classes, see this Jira entry.

提交回复
热议问题