On Thu, Jul 8, 2021 at 8:49 AM Kees Kuip <[email protected]> wrote: > > > The serialization of inner classes works fine if the inner-class definition > is in the same class. > This works: > <pre> > static class Person{ > public String name; > public Address address = new Address(); > > class Address{ > public String city; > public Address({ > } > } > } > </pre> > > But deserialization of a the subclass of person fails. > <pre> > static class Person2 > extends Person{ > public Address address2 = new Address(); > } > </pre> > > The fail message is: > com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot > construct instance of `Test$Person$Address`: non-static inner classes like > this can only by instantiated using default, no-argument constructor > > Anybody knows how to fix this problem? (I do not want to create a static > inner class though)
The underlying reason is due to non-static inner classes having a hidden "parent-this" pointer, linking to the enclosing class. You can look at the class file generated for that inner class to see this extra argument to the constructor. There is no way to support this in general, now or in future. It is a fundamental limitation. -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10hOZuhx66yM%2BOpthUN9CNgQhTc1qem7NkoaRw1007OtSA%40mail.gmail.com.
