there are still 2 javax.annotation imports in my generated code after using useJakartaValidation
DenWin opened this issue · comments
Hi, I using jsonschema2pojo as following:
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/jsonschema</sourceDirectory>
<targetPackage>de.example.schema</targetPackage>
<sourceType>jsonschema</sourceType>
<dateTimeType>java.time.OffsetDateTime</dateTimeType>
<includeJsr303Annotations>true</includeJsr303Annotations>
<includeJsr305Annotations>true</includeJsr305Annotations>
<generateBuilders>true</generateBuilders>
<useJakartaValidation>true</useJakartaValidation>
<removeOldOutput>true</removeOldOutput>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
thought in my generated code I still find the following:
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
...
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
@JsonProperty("_id")
@NotNull
@Nonnull
private String id;
@Nullable
@JsonProperty("_modtime")
private OffsetDateTime modtime;
- There exist NonNull coming from javax beside NotNull from jakarta.
- Nullable only exists coming from javax
- and worst the imports to javax
I would assume:
- For NotNull vs NonNull a Rule similar to ValidRule is required.
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()) {
final Class<? extends Annotation> notClass
= ruleFactory.getGenerationConfig().isUseJakartaValidation()
? NotNull.class
: javax.annotation.Nonnull.class;
field.annotate(notClass);
}
return field;
}
Well one thing I'm still a little unsure, are perhaps both annotations required?
- For Nullable it goes a little further as the jaakarta-version of nullable needs to be added in the import
Hi
useJakartaValidation
does not mean that there won't be any javax.*
import anymore.
Configuration provided has both includeJsr303Annotations
(Bean Validation) as well as includeJsr305Annotations
(Annotations for Software Defect Detection [status: dormant]) the latter is the "cause" for javax.annotation.*
imports whilst former is "driven" by useJakartaValidation
configuration option.
Well one thing I'm still a little unsure, are perhaps both annotations required?
It depends whether jsr305 (com.google.code.findbugs:jsr305
) annotations are being used for static code analysis in project at hand or not.