Let's say I have class A, with a field of the same type (class A { A test; }). I need to refer to test in Json as an identifier, like {"test": 123}, which means I need a custom JsonDeserializer for A. However, registering a custom deserializer for A and then deserializing makes it call the custom deserializer for the entire root object since it's also of type A, which makes it impossible to proceed. Is there any way around this?
#Custom deserializer for fields of root type with Gson
4 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @warm osprey! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Managed to do it with a combination of a TypeAdapter, TypeAdapterFactory, and Gson#getDelegateAdapter.