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

[Task] Add new constructor for jackson classes with only all mandatory field(s) #535

Open
MelleD opened this issue Feb 28, 2024 · 2 comments
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. task

Comments

@MelleD
Copy link
Contributor

MelleD commented Feb 28, 2024

Is your task related to a problem? Please describe.
Currently there is only one constructor that contains all fields. This makes instantiating larger classes cumbersome and difficult to read. A good practice is to have a constructor that includes all mandatory fields and leaves out the optional ones because they can be set if necessary.

Example:

public class Person {

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

        public Person (String name, Optional<String> lastname, int age)
        {
        //..
        }

Describe the solution you'd like

public class Person {

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

        public Person (String name, int age)
        {
        //..
        }
@MelleD MelleD added the task label Feb 28, 2024
@chris-volk chris-volk changed the title [Task] Add new constructor for jackson classes with all mandatory field(s) [Task] Add new constructor for jackson classes with only all mandatory field(s) Mar 19, 2024
@chris-volk chris-volk added the acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. label Mar 19, 2024
@chris-volk
Copy link
Contributor

@MelleD , Would it solve your issue to include lombok and allow such constructors by setting lombok annotations?

@MelleD
Copy link
Contributor Author

MelleD commented Apr 9, 2024

Would it solve your issue to include lombok and allow such constructors by setting lombok 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. task
Projects
None yet
Development

No branches or pull requests

2 participants