Skip to content

Allow Savables to be loaded by static builder methods #2621

@codex128

Description

@codex128

Currently Savables are required to have a parameterless constructor in order to be deserialized by a JmeImporter. This puts some fairly major restrictions on how classes are implemented, even ones that don't implement Savable. I think this can be fixed by allowing Savable classes to specify a static builder method, which is responsible only for instantiating the Savable from the InputCapsule. Further deserialization is performed using the normal read method.

public class MySavable implements Savable {
    @SavedObjectBuilder
    public static Savable loadSave(InputCapsule in) throws IOException {
        return new MySavable(in.readInt("value", 0));
    }
}

I've already managed to implemented this on my vulkan fork without any outright breaking changes, so I am curious if this is something we want in jme3 (or whether we want this at all).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions