ExJson / xjs-data

A set of tools for manipulating plain JSON-like data
GNU Lesser General Public License v2.1
1 stars 1 forks source link

About class object serialization #1

Open Treetrain1 opened 5 months ago

Treetrain1 commented 5 months ago

Is there a way to serialize class objects and transform the output of a serialized class?

I found an implementation for class object serialization in CatLib called XjsObjectMapper or something similar. Is there a way to take a class and convert it to xjs with modified serialization?

I’m looking for something similar to Gson or Jankson’s ability to register serializers and deserializers.

Here’s an example of what I’m asking: Can I transform the output from the following class to use the codec (from Mojang’s DataFixerUpper) from the TypedEntry instance? (Method of finding the correct codec to use for deserialization not shown because it’s a bit complicated)

public class SerializableObject {
    private static final TypedEntryType<CustomObject> CUSTOM_TYPE = new TypedEntryType<>(CustomObject.CODEC);

    public String serializedString; // serialized normally
    public TypedEntry<CustomObject> customObject; // uses the codec from CUSTOM_TYPE
}
public record TypedEntryType<T>(Codec<T> codec) {}
public record TypedEntry<T>(TypedEntryType<T> type, T value) {}
PersonTheCat commented 5 months ago

This feature is planned for xjs-databind, but I'm just not there yet. Here's the quick roadmap for right now:

  1. Finish testing xjs-data (basic serializers)
  2. Migrate xjs-compat to xjs-data (hjson, ubjson, etc)
  3. Implement xjs-lang, a std library for xjs, the jvm language
  4. Repurpose xjs-core as the xjs compiler before 1.0
  5. Implement serialization utils and other data-from-json code in xjs-databind

Steps 1-3 are well in progress, but step 4 is not. Step 2 also includes migrating CatLib to the new xjs-data, which itself is a part of the port to 1.20+. As you can imagine, that will take quite some time to get to.

Short answer: not yet

If you are interested in this project, please consider contributing.

Treetrain1 commented 5 months ago

I see. It looks like that’s going to take a while to do.

I may try to help with this project after I finish a personal project. Definitely interested for where this goes.