eclipse-esmf / esmf-sdk

Load Aspect Models and their artifacts as Java code; share components to realize SAMM as code
https://eclipse-esmf.github.io/esmf-developer-guide/index.html
Mozilla Public License 2.0
24 stars 12 forks source link

[Task] Add fluent api to create jackson classes #534

Open MelleD opened 5 months ago

MelleD commented 5 months ago

Is your task related to a problem? Please describe. As a developer I would like to have a fluent API to create the jackson classes to have some advantages in the code. The advantages lie in the easier development of useful programs and the better readability of the program code written for them. Fluent interfaces can come very close to a natural language sentence. This means you only need to add a little additional comment.

Example:

public class Person {

    @NotNull
    @Pattern(regexp = "[0-9A-Z]{4}")
    private String name;
    private Optional<String> lastname;
        private int age;

Currently

Person person = new Person();
person.setName("Dennis");
person.setLastname(Optional.of("Melle"));
person.setAge(21); // :-)

Describe the solution you'd like I would like to have fluent api directly in the classes

Person person = new Person();

person.name("Dennis")
.lastname("Melle");
.age(21); 

or

Person person = new Person()
                            .name("Dennis")
                            .lastname("Melle");
                            .age(21); 

Describe alternatives you've considered Maybe a builder api could also make sense

Person.Builder builder = Person.Builder();
Person person = builder.name("Dennis")
                            .lastname("Melle");
                            .age(21).build();
chris-volk commented 4 months ago

@MelleD , Would it solve your issue to include lombok to add builder or fluent with the according annotations?

MelleD commented 4 months ago

Would it solve your issue to include lombok to add builder or fluent with the according annotations?

I don't know if it's a good idea to have a hard dependency on Lombok. We are currently not using Lombok and there are currently no needs for Lombok.