jMonkeyEngine / jMonkeyEngine/jmonkeyengine

Allow Savables to be loaded by static builder methods

Open
#2,621 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request / Proposal Needs investigation
Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JmeImporter deserialization path and the existing parameterless construction of Savable classes. Read the Savable read method and InputCapsule usage alongside the proposed @SavedObjectBuilder entry point. Done means a Savable can be instantiated through a static builder and then receive normal deserialization without requiring a parameterless constructor.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.