my goal is to avoid problem 'Private field is never assigned' without using @SupressWarnings or creating a defined constructor.
I am aware using annotation will lead to technical debt for the long run. However, I can't not justify the Java verbosity (although I love it at times when debugging a bug), this code is easier to read.
Method that I do not wish to use:
SupressWarnings("unused")
written above the class statement.- Creating a defined constructor which is not necessary since MyBatis can modify the object attribute regardless there is a setters or not for example when you use
@SelectKey
. - Creating a setter which will never be used.
This is the sample code for the model I am going to standardize for MyBatis.
model/NameModel.java
package com.example.mssqlserver.model;
import com.fasterxml.jackson.annotation.JsonInclude;
@SuppressWarnings("unused") // MyBatis does not need a defined constructor nor a setters.
@JsonInclude(JsonInclude.Include.NON_NULL) // filter: only non_null, alternative: spring.jackson.default-property-inclusion=NON_NULL in application.properties
public class NameModel {
private Integer id;
private String name;
private String newid;
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public String getNewid() {
return newid;
}
public boolean requestIsValid() {
return !this.name.isEmpty();
}
}