withId() is generated in fromJson implementation, despite that it's not present on Resource or ProxyResource
id, name, etc... in Resource cannot be accessed in child classes
Current generated code:
if ("id".equals(fieldName)) {
deserializedDedicatedHostGroupInner.withId(reader.getString());
} else if ("name".equals(fieldName)) {
deserializedDedicatedHostGroupInner.withName(reader.getString());
} else if ("type".equals(fieldName)) {
deserializedDedicatedHostGroupInner.withType(reader.getString());
}
Proposals:
Solution 1: Add protected setters in Resource/ProxyResource
Pros
Seemingly the most simple to implement. In fact, current codegen's working like magic as it assumes setter methods on parent classes. There's not much(if not none) codegen work involved.
Cons
Protected setter methods are exposed though all Resource/ProxyResource's subclasses.
Solution 2: Add protected constructors in Resource/ProxyResource
Pros
Exposed less amount(1 vs 3) protected methods than the setter
Preserves the "read-only" nature of these properties, compared to "setter"
Cons
Protected constructor is exposed any way.
mgmt doesn't have constructors with parameters for now
Way more things to implement than protected setters.
Access helpers are defined in implementation packages and should be defined in the package implementation.accesshelpers
Similar as above, instead of exposing protected methods, it exposes unnecessary public Accessor Helper class.
Personal preference
From API's perspective, I prefer solution 3, which is the shadowing approach. It doesn't expose unnecessary APIs. Additionally, this may be consistent with the general case https://github.com/Azure/autorest.java/issues/2741, e.g. if the property is from parent and no public setter available, we shadow/duplicate it in child classes.
Haven't dived deep into each of the implementation. I assume all the solutions except solution 1(protected setters) involve getting some information of the base class(Resource/ProxyResource) to determine property's access pattern.
Issue
withId()
is generated infromJson
implementation, despite that it's not present onResource
orProxyResource
id
,name
, etc... inResource
cannot be accessed in child classesCurrent generated code:
Proposals:
Solution 1: Add protected setters in
Resource
/ProxyResource
Pros
Cons
Resource
/ProxyResource
's subclasses.Solution 2: Add protected constructors in
Resource
/ProxyResource
Pros
Cons
Solution 3: Shadowing
id
,name
, etc... in child classes, similar to https://github.com/Azure/autorest.java/pull/2639Pros
Cons
Solution 4: Move
ProxyResourceAccessor
out of implementation packagePros
Cons
Personal preference
From API's perspective, I prefer solution 3, which is the shadowing approach. It doesn't expose unnecessary APIs. Additionally, this may be consistent with the general case https://github.com/Azure/autorest.java/issues/2741, e.g. if the property is from parent and no public setter available, we shadow/duplicate it in child classes. Haven't dived deep into each of the implementation. I assume all the solutions except solution 1(protected setters) involve getting some information of the base class(
Resource
/ProxyResource
) to determine property's access pattern.