Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified Fields Tracking for Setters #3763

Open
funkrusher opened this issue Oct 17, 2024 · 0 comments
Open

Modified Fields Tracking for Setters #3763

funkrusher opened this issue Oct 17, 2024 · 0 comments

Comments

@funkrusher
Copy link

funkrusher commented Oct 17, 2024

Describe the feature

An annotation that automatically makes the tracking of "modified fields" possible.
A "modified field" is a field of which the setter-function has been called at least once in the lifetime of the object-instance.

MyPojo {

    private Map<String, Object> modifiedFields = new HashMap<>();

    private String test;
    ....

    public MyPojo setTest(String test) {
        this.test = test;
        this.modifiedFields.put("test", test);
        return this;
    }
    ....
    public Map<String, Object> getModifiedFields() {
        return this.modifiedFields;
    }
}

Given that Pojos are often created during Deserialization (given data from a (rest)-endpoint, or from an import-file) / when external systems call the java-backend (for example with a REST-PATCH method call).

To support REST-PATCH it is necessary to be able to detected which of the incoming data-fields have really been given by the caller to decide (via openapi definition) if those fields are required=true/false. If they are not not required they may also be missing from the request, but if they are required, they must either provide a value or NULL as a value (which is also a valid value)

The modified-fields would help to be able to check in the code if a field has been set by the caller. For example

    if (pojo.getModifiedFields().contains("test") {
        update.set("test", pojo.getTest());
    }

Describe the target audience

  • Java Programmers wanting to implement REST PATCH Api (PATCH needs the ability of modified fields tracking)
  • Java Programmers wanting to create dynamic imports that only process data from fields in import-files (JSON, XML, ...) that have really been given

Additional context
An annotation on the class-level would be helpful. For example:

@SettersWithTracking
MyPojo {
    ...
}

If an interest is there to implement this feature, i would also think about helping implementing it in lombok / discussing it further (this is only a very raw concept)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant