In Child class, toJson can't access parent class's flattened property getter, as the getter is private(no matter whether they are in the same package)
In Child class, fromJson can't access parent class's flattened property setter, as it's package private and parent class is in a different package
Parent class:
// parent class in different package
public class PirCommunityGalleryResource implements JsonSerializable<PirCommunityGalleryResource> {
private CommunityGalleryIdentifier innerIdentifier;
private CommunityGalleryIdentifier innerIdentifier() {
return this.innerIdentifier;
}
PirCommunityGalleryResource withInnerIdentifier(CommunityGalleryIdentifier innerIdentifier) {
this.innerIdentifier = innerIdentifier;
return this;
}
public String uniqueId() {
return this.innerIdentifier() == null ? null : this.innerIdentifier().uniqueId();
}
public PirCommunityGalleryResource withUniqueId(String uniqueId) {
if (this.innerIdentifier() == null) {
this.innerIdentifier = new CommunityGalleryIdentifier();
}
this.innerIdentifier().withUniqueId(uniqueId);
return this;
}
}
Child class:
// child class in different package
public final class CommunityGalleryInner extends PirCommunityGalleryResource {
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
// `innerIdentifier()` can't be accessed, as it is private
jsonWriter.writeJsonField("identifier", innerIdentifier());
return jsonWriter.writeEndObject();
}
public static CommunityGalleryInner fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
CommunityGalleryInner deserializedCommunityGalleryInner = new CommunityGalleryInner();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("identifier".equals(fieldName)) {
// `withInnerIdentifier()` can't be accessed, as parent class is in a different package and the method is package private
deserializedCommunityGalleryInner.withInnerIdentifier(CommunityGalleryIdentifier.fromJson(reader));
} else {
reader.skipChildren();
}
}
return deserializedCommunityGalleryInner;
});
}
}
toJson
can't access parent class's flattened property getter, as the getter is private(no matter whether they are in the same package)fromJson
can't access parent class's flattened property setter, as it's package private and parent class is in a different packageParent class:
Child class:
This is similar to the discriminator issue, which we solved by shadowing the discriminator in child class: https://github.com/Azure/autorest.java/pull/2639
We could do similar things here, though we may need to also override parent flatten properties getter and setter, e.g. in child class: