Closed GoogleCodeExporter closed 9 years ago
We have several tests that thoroughly tests the expected behavior around inner
classes. Is this a static inner class or a regular inner class? For regular
inner
classes, Gson would have no way of constructing the instance because of the
needed
reference to the outer class. You will need to register an InstanceCreator.
Please provide a code sample so that we can reproduce the bug.
Original comment by inder123
on 27 Dec 2008 at 1:35
On a somewhat related note, I have added the ability to exclude all "inner
classes"
from serialization/deserialization in r350.
This is useful if you have many classes that contain an inner class, but you do
not
want to write custom serializers for each of these classes. This feature would
help
the user above assuming that they do not want this inner class as part of the
serialization/deserializaiton and they have a default constructor (or Instance
Creator) for the outer class. The latter assumption must be correct since it is
attempt to deserialize the field.
FYI, a "static nested class" is not an "inner class".
Original comment by joel.leitch@gmail.com
on 28 Dec 2008 at 3:54
This got me too - But Joel's comment about a "static nested class" vs "inner
class"
gave me the clue I needed to solve the problem.
Even if you create a no-args constructor in your inner class it still throws an
exception saying it can't find one.
It might be worth mentioning in the User Guide that to use an inner class it
needs to
be static or GSON won't be able to find the constructor. Alternatively can the
code
that looks for the constructor in MappedObjectConstructor check for this
somehow and
throw a more informative exception message?
Original comment by dirk.mcc...@gmail.com
on 24 Jun 2009 at 3:22
Changed the User Guide to highlight this fact a little more. See the "Nested
Classes" section.
Original comment by joel.leitch@gmail.com
on 29 Sep 2009 at 8:45
Changed the User Guide to highlight this fact a little more. See the "Nested
Classes" section.
Original comment by joel.leitch@gmail.com
on 29 Sep 2009 at 8:45
Original issue reported on code.google.com by
miku.kop...@gmail.com
on 27 Dec 2008 at 11:07