StackOverflow when serializing non-static inner class
While serializing a class consisting only of nested POJOs, primitives, lists, maps and enums, this error occurs.
I wrote out the entire stucture of this file below, as one last sanity check. There's nothing very unusual.
Structure
POJO { static Logger static Jankson static File (config file)
POJO {
enum (3 values, all named with @SerializedName)
enum (4 values, all named with @SerializedName)
6 doubles
7 booleans
String
3 methods (not annotated)
}
POJO {
8 ints
2 doubles
8 booleans
String
2 Lists of Strings
3 enums (3 values each, all named with @SerializedName)
method (not annotated) } POJO { 2 doubles 7 booleans (nested object with custom (de)serializers has removed) } POJO { 5 booleans int }
enum (2 values, both named with @SerializedName)
HashSet of enum (7 values, all named with @SerializedName) (I've tried replacing this with ArrayList too)
enum (4 values, all named with @SerializedName)
3 booleans
String
enum (6 values, all named with @SerializedName)
HashMap of enum (10 values, all named with @SerializedName) to Float
enum (3 values, all named with @SerializedName)
static method (load) (not annotated) method (save) (not annotated) method (not annotated) }
Stacktrace
java.lang.StackOverflowError: null
at java.lang.Class.privateGetDeclaredMethods(Class.java:3396) ~[?:?]
at java.lang.Class.getDeclaredMethods(Class.java:2504) ~[?:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:332) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
... You get the idea
Caused by a non-static inner class (implicit reference to super class)
Amazingly, this is now fixed in 2.0. Synthetic instance fields starting with this$ are the culprit, and are possible to filter out.