If class doesn't have a default constructor, reading fails silently
Closed this issue · 2 comments
I had a data class that had a constructor, but I didn't manually add a default constructor, and as a result, when doing .fromJson(object, class)
it just returns null with no indication of why it was null
have you tried fromJsonCarefully?
To elaborate: Jankson tries the best it can to load everything perfectly without throwing - but things will go wrong. A lot. Marshalling data into POJOs is a pretty intense hack, and I avoid some of the scarier hacks Gson does. In the case you present, Gson can create a new instance without calling any constructor, possibly resulting in a malformed or uninitialized instance.
If you want to get feedback from Jankson, I strongly recommend using the *Carefully methods, as that will proactively throw when anything goes wrong.