Skip to content

Commit

Permalink
Generating Jackson serializers for concrete classes only
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Oct 25, 2024
1 parent e01bb78 commit c47d5ba
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Collection<String> create(Collection<ClassInfo> classInfos) {

private Optional<String> create(ClassInfo classInfo) {
String beanClassName = classInfo.name().toString();
if (vetoedClassName(beanClassName) || !generatedClassNames.add(beanClassName)) {
if (vetoedClass(classInfo, beanClassName) || !generatedClassNames.add(beanClassName)) {
return Optional.empty();
}

Expand Down Expand Up @@ -145,7 +145,11 @@ protected static String ucFirst(String name) {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}

protected static boolean vetoedClassName(String className) {
protected static boolean vetoedClass(ClassInfo classInfo, String className) {
return classInfo.isAbstract() || classInfo.isInterface() || vetoedClassName(className);
}

private static boolean vetoedClassName(String className) {
return className.startsWith("java.") || className.startsWith("jakarta.") || className.startsWith("io.vertx.core.json.");
}

Expand Down Expand Up @@ -203,11 +207,9 @@ private void registerTypeToBeGenerated(Type type) {
}

private void registerTypeToBeGenerated(String typeName) {
if (!vetoedClassName(typeName)) {
ClassInfo classInfo = jandexIndex.getClassByName(typeName);
if (classInfo != null && shouldGenerateCodeFor(classInfo)) {
toBeGenerated.add(classInfo);
}
ClassInfo classInfo = jandexIndex.getClassByName(typeName);
if (classInfo != null && !vetoedClass(classInfo, typeName) && shouldGenerateCodeFor(classInfo)) {
toBeGenerated.add(classInfo);
}
}

Expand Down Expand Up @@ -312,8 +314,14 @@ private String fieldNameFromMethod(MethodInfo methodInfo) {
}

boolean hasUnknownAnnotation() {
return annotations.keySet().stream()
.anyMatch(ann -> ann.startsWith("com.fasterxml.jackson.") && !ann.equals(JsonProperty.class.getName()));
return annotations.keySet().stream().anyMatch(FieldSpecs::isUnknownAnnotation);
}

private static boolean isUnknownAnnotation(String ann) {
if (ann.startsWith("com.fasterxml.jackson.")) {
return !ann.equals(JsonProperty.class.getName());
}
return false;
}

ResultHandle toValueWriterHandle(BytecodeCreator bytecode, ResultHandle valueHandle) {
Expand Down

0 comments on commit c47d5ba

Please sign in to comment.