Why is Spring Data MongoDB unable to instantiate this nested type structure?

前端 未结 2 719
予麋鹿
予麋鹿 2021-02-07 17:50

My document structure is like:

{
    _id: \"A\",
    groups:[{
        groupId: \"someId\",
        groupName: \"someName\",
        params: {
            type1:         


        
2条回答
  •  情书的邮戳
    2021-02-07 18:17

    This seems to be an issue with doubly nested inner classes and the synthetically generated constructors created by the compiler. I could reproduce that issue locally and see if we can provide a fix. In the meantime you have two options:

    1. Turn the inner class into static ones as this will remove the synthetic constructors and instantiation will work correctly.
    2. Nest the type declarations in the same way you nest the properties. I.e. move the ParamData class into the Group class, DataConfig into Config as that will cause the synthetic constructors created in a way they match instantiation order Spring Data currently relies on.

    I'd suggest the former approach as it doesn't artificially bind the classes to instances of the outer class.

提交回复
热议问题