Closed weidongxu-microsoft closed 5 months ago
package private won't work, as class could be in different package.
option3, just add
this.updatedProperties.add("kind");
to subclass ctor, after call superclass setKind
.
Final decision in 2024.3.1 Meeting:
In the subclass, e.g. Shark
, we add updatedProperties.add("kind")
to the ctor. Code like below:
/**
* Creates an instance of Shark class.
*/
@Generated
public Shark() {
this.updatedProperties.add("kind");
setKind("shark");
}
Background
https://github.com/Azure/autorest.java/pull/2576#discussion_r1504012383
Shark
hasupdatedProperties
which shadowsFish
'supdatedProperties
. And in the ctor ofShark
, it callsFish
'ssetKind()
, which updatedFish
'supdatedProperties
. In the highlighted line in above code snippet, when serialize forresource.fish
, it callsshark.toJsonMergePatch()
, but askind
is not added to shark's updatedProperties, but to fish's updated properties. So kind is not serialized.test: https://github.com/Azure/autorest.java/tree/main/typespec-tests/src/main/java/com/cadl/patch/models service using this: communication jobrouter
Design
Option1:
Make
updatedProperties
from base class asprotected
, and remove overrideupdatedProperties
from sub class. Thusthis.updatedProperties
in sub class will get base classs' updatedProperties.Pros: Implementation is easy Cons: Once we make
updatedProperties
asprotected
, we can't change back.Option2:
Check both base class and sub class's
updatedProperties
in sub class'stoJsonMergePatch()
logic.Pros: Will not change the current class's public APIs. Cons: Implementation is a bit complex, we will need to check all the super classes'
updatedProperties
.Option3:
Add
kind
(private) property,setKind()
(private) andgetKind()
(public) method to sub class, and when callingsetKind
method, it will update sub class'supdatedProperties
.Pros: generated code's logic is clear and simple, does not need to consider about the shaddowed property thing. Cons: We will need to add APIs to sub class.
kind
appears will both in sub class and base class.Personaly I would prefer option 1, as we already make
kind
in parent class protected. Guess we can also makeupdatedProperties
as `protected.