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 24, 2024
1 parent e01bb78 commit a71ff9f
Showing 1 changed file with 17 additions and 12 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 @@ -112,9 +112,9 @@ protected void classFields(ClassInfo classInfo, Collection<FieldInfo> fields) {

protected <T> T onSuperClass(ClassInfo classInfo, Function<ClassInfo, T> f) {
Type superType = classInfo.superClassType();
if (superType != null && !vetoedClassName(superType.name().toString())) {
if (superType != null) {
ClassInfo superClassInfo = jandexIndex.getClassByName(superType.name());
if (superClassInfo != null) {
if (superClassInfo != null && !vetoedClass(superClassInfo, superType.name().toString())) {
return f.apply(superClassInfo);
}
}
Expand Down Expand Up @@ -145,8 +145,9 @@ protected static String ucFirst(String name) {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}

protected static boolean vetoedClassName(String className) {
return className.startsWith("java.") || className.startsWith("jakarta.") || className.startsWith("io.vertx.core.json.");
protected static boolean vetoedClass(ClassInfo classInfo, String className) {
return classInfo.isAbstract() || classInfo.isInterface() || className.startsWith("java.")
|| className.startsWith("jakarta.") || className.startsWith("io.vertx.core.json.");
}

protected enum FieldKind {
Expand Down Expand Up @@ -203,11 +204,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 +311,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 a71ff9f

Please sign in to comment.