Marrying together Configurate and Gson

This is to do with a previous post of mine ( Configurate & Polymorphism - #2 by HaedHutner ) which after going unanswered for a while, I’ve gotten more or less desperate for a solution.

I have a number of questions which I hope will allow me to create a reliable link between Configurate and Gson, allowing me to use Gson’s RuntimeTypeAdapterFactory as a solution to the problem I described in that thread.

  1. Is there a common interface which is implemented by all classes which are serializable via Configurate?

  2. How does one take a Json ConfigurationNode and turn it into a String?
    2.1. Bonus points for the ability to just straight up turn it into a JsonElement for use with Gson

  3. What about the reverse? Is there a way to turn a Json string into a ConfigurationNode?

I would appreciate any answer to these questions. I have been rummaging through the documentation and the code, and I have been unable to find anything. Please and thank you.

  1. & 3.: Use the json part of configurate, and set the sink/source to a reader/writer, which simply is a String/outputs a String.
1 Like

There is not a common interface implemented by classes. The classes need to either be annotated with @ConfigSerializable using @Setting to mark serialized fields, or the settings that the ConfigurationLoader uses needs to have a TypeSerializer registered for that type.

A ConfigurationLoader does not need a file, just some sort of sink and source. Which ones they are doesn’t matter. This means that you could write to a string by setting the sink to a StringWriter, or read from a string by setting the source to a StringReader.

1 Like