-
Notifications
You must be signed in to change notification settings - Fork 34
Stag cannot access inherited members if the classes are in different packages #60
Comments
A possible solution I'll put down before I forget it: Since Basically... class ClassB$TypeAdapter {
T <T extends ClassB> parse(Json, Instantiator<T>) {
T object = Instantiator.instantiate();
object.field2 = "stuff";
return object.
}
}
class ClassA$TypeAdapter {
ClassA parse(Json) {
ClassA object = ClassB$TypeAdapter.parse(Json, ClassA.instantiator);
object.field = "more stuff";
return object;
}
} This seems potentially very complicated, so maybe it would be better to just enforce public fields if a descendent class type adapter can't access parent fields. |
Agree with you that in these cases we should just enforce public methods. |
Related to this bug, if a class has a static member class that is non-public, or itself is non-public, Stag will fail to compile as it cannot access the inner class from the generated @UseStag
public class ClassA {
@UseStag
static class ClassB {
String field.
}
} The solution here is just to require a class annotated with |
Issue Summary
If
ClassA
extendsClassB
and inherits fields, stag will collect all the inherited fields and use them in the creation of an object. IfClassA
extendsClassB
, which is in a different package thanClassA
, and the members ofClassB
are protected or package local (legal according to stag rules), then the type adapter forClassA
will not be able to access them.Reproduction Steps
Take the following two classes. The generated
ClassA$TypeAdapter
will not be able to accessfield2
.Expected Behavior
Stag should either be able to access the fields, or should enforce a rule requiring classes that are extended to make their members public.
Actual Behavior
Given the example above, the generated
ClassA$TypeAdapter
will not be able to accessfield2
.The text was updated successfully, but these errors were encountered: