micronaut-serialization
micronaut-serialization copied to clipboard
KSP generate incorrect Introspection class when SerdeImport java classes and parent class use protected field
Expected Behavior
Should generate the same Introspection class as java serde annotation processor
Actual Behaviour
doesn't define protected field like
case 2:
throw new UnsupportedOperationException("Cannot mutate property [a] that is not mutable via a setter method, field or constructor argument for type: com.rakuten.rapid.rmock.model.TestB");
default:
throw this.unknownDispatchAtIndexException(var1);
Steps To Reproduce
TestA.java
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode
@Data
public class TestA {
protected String a; // only protected will have issue
}
TestB.java
@EqualsAndHashCode(callSuper = true)
@Data
public class TestB extends TestA{
private String b;
}
ConfigController.kt
@SerdeImport(TestA::class)
@SerdeImport(TestB::class)
It will generate different Introspection class like
protected final Object dispatchOne(int var1, Object var2, Object var3) {
switch (var1) {
case 0:
return ((TestB)var2).getB();
case 1:
((TestB)var2).setB((String)var3);
return null;
case 2:
throw new UnsupportedOperationException("Cannot mutate property [a] that is not mutable via a setter method, field or constructor argument for type: com.rakuten.rapid.rmock.model.TestB");
default:
throw this.unknownDispatchAtIndexException(var1);
}
}
If use java annotation processor, it will generate
protected final Object dispatchOne(int var1, Object var2, Object var3) {
switch (var1) {
case 0:
return ((TestB)var2).getA();
case 1:
((TestB)var2).setA((String)var3);
return null;
case 2:
return ((TestB)var2).getB();
case 3:
((TestB)var2).setB((String)var3);
return null;
default:
throw this.unknownDispatchAtIndexException(var1);
}
}
Environment Information
macOS JDK21
Example Application
No response
Version
4.7.6
Please test without Lombok. If it's still broken please create a reproducer.
reproducer in https://github.com/semistone/micronaut_ksp_issue_reproduce