If your class has a default constructor (even an empty one), your
first pattern (initializing the instances variables where they are
defined instead of in the constructor) should work fine. If your class
does not have a default constructor, I believe (I could be wrong) that
Gson manually tries to allocate the object, which would skip any
initialization at all. This will actually fail on some platforms (I
have seen posts to that effect about Android allocations failing).
So you should always make sure Gson-constructed classes have a default
constructor. It may be that putting the code you showed in the default
constructor worked not because you moved the code around, but because
you had a default constructor at all.
> --
> You received this message because you are subscribed to the Google Groups "google-gson" group.
> To post to this group, send email to
googl...@googlegroups.com.
> To unsubscribe from this group, send email to
google-gson...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/google-gson?hl=en.
>