client, add shadow variable for discriminator property#2639
Conversation
| if (!property.isPolymorphicDiscriminator()) { | ||
| superPropertyConsumer(property, superRequiredProperties, superConstructorProperties, | ||
| superReadOnlyProperties, superSetterProperties, settings); | ||
| hasRequiredProperties |= property.isRequired(); | ||
| } |
There was a problem hiding this comment.
Treat polymorphic discriminator property as a property in current model.
| ? JavaVisibility.Private | ||
| : JavaVisibility.Public; | ||
|
|
||
| if (!property.isPolymorphicDiscriminator() || modelDefinesProperty(model, property)) { |
There was a problem hiding this comment.
Here code change is just removing the condition (since we no longer skip the discriminator property).
| * The @data.kind property. | ||
| */ | ||
| @Generated | ||
| private String type = "bytes"; |
There was a problem hiding this comment.
My origin attempt is to avoid this String type class variable, and directly provide
@Generated
@Override
public String getType() {
return "bytes";
}(there is a corner case on behavior difference between the 2, on a case of user directly do BinaryData("<invalid-json>").toObject(BytesData.class) with a JSON of unknown type)
But reverted to current shadow variable.
Reason is fromJson have code on either deserializedBytesData.setType(..) or deserializedBytesData.type = .., and I don't want to disrupt that part of code.
| */ | ||
| @Generated | ||
| @Override | ||
| public String getType() { |
There was a problem hiding this comment.
I assume, in subclass, adding/removing the "override" of getType() in exact same method signature won't be breaking changes.
There was a problem hiding this comment.
https://revapi.org/revapi-java/0.28.1/differences.html#java.method.movedToSuperClass
"Method Moved To Superclass" is "equivalent". So I think this won't be counted as break.
73bd5ea to
46e8d58
Compare
ba5de45 to
5b9c17e
Compare
| public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { | ||
| jsonWriter.writeStartObject(); | ||
| jsonWriter.writeIntField("age", getAge()); | ||
| jsonWriter.writeStringField("kind", getKind()); |
There was a problem hiding this comment.
Just notice serialziation and deserialization part, wonder why this get removed?
another fix on #2574
Remove
setKindmethod in superclass.Shadow
kindvariable in subclass.Override
getKindmethod in subclass.code change https://github.com/Azure/autorest.java/pull/2639/files/e9c1c0dbad94325dacb299fc8f29a1d6c892fd7b..db632bbb53ab4612517996b0298ea42f44824de1
test like this (for both azure-json and Jackson) e9c1c0d