diff --git a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelBuildOperationDetails.java b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelBuildOperationDetails.java index 04e32ede9a..2b46389ebb 100644 --- a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelBuildOperationDetails.java +++ b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelBuildOperationDetails.java @@ -18,6 +18,11 @@ */ @Fluent public final class DocumentModelBuildOperationDetails extends OperationDetails { + /* + * Type of operation. + */ + private String kind = "documentModelBuild"; + /* * Operation result upon success. */ @@ -27,7 +32,16 @@ public final class DocumentModelBuildOperationDetails extends OperationDetails { * Creates an instance of DocumentModelBuildOperationDetails class. */ public DocumentModelBuildOperationDetails() { - setKind("documentModelBuild"); + } + + /** + * Get the kind property: Type of operation. + * + * @return the kind value. + */ + @Override + public String getKind() { + return this.kind; } /** @@ -146,11 +160,11 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getLastUpdatedDateTime())); jsonWriter.writeStringField("resourceLocation", getResourceLocation()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeNumberField("percentCompleted", getPercentCompleted()); jsonWriter.writeStringField("apiVersion", getApiVersion()); jsonWriter.writeMapField("tags", getTags(), (writer, element) -> writer.writeString(element)); jsonWriter.writeJsonField("error", getError()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeJsonField("result", this.result); return jsonWriter.writeEndObject(); } @@ -184,8 +198,6 @@ public static DocumentModelBuildOperationDetails fromJson(JsonReader jsonReader) reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); } else if ("resourceLocation".equals(fieldName)) { deserializedDocumentModelBuildOperationDetails.setResourceLocation(reader.getString()); - } else if ("kind".equals(fieldName)) { - deserializedDocumentModelBuildOperationDetails.setKind(reader.getString()); } else if ("percentCompleted".equals(fieldName)) { deserializedDocumentModelBuildOperationDetails .setPercentCompleted(reader.getNullable(JsonReader::getInt)); @@ -196,6 +208,8 @@ public static DocumentModelBuildOperationDetails fromJson(JsonReader jsonReader) deserializedDocumentModelBuildOperationDetails.setTags(tags); } else if ("error".equals(fieldName)) { deserializedDocumentModelBuildOperationDetails.setError(Error.fromJson(reader)); + } else if ("kind".equals(fieldName)) { + deserializedDocumentModelBuildOperationDetails.kind = reader.getString(); } else if ("result".equals(fieldName)) { deserializedDocumentModelBuildOperationDetails.result = DocumentModelDetails.fromJson(reader); } else { diff --git a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelComposeOperationDetails.java b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelComposeOperationDetails.java index 6b2a0d8005..d962c4eb6c 100644 --- a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelComposeOperationDetails.java +++ b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelComposeOperationDetails.java @@ -18,6 +18,11 @@ */ @Fluent public final class DocumentModelComposeOperationDetails extends OperationDetails { + /* + * Type of operation. + */ + private String kind = "documentModelCompose"; + /* * Operation result upon success. */ @@ -27,7 +32,16 @@ public final class DocumentModelComposeOperationDetails extends OperationDetails * Creates an instance of DocumentModelComposeOperationDetails class. */ public DocumentModelComposeOperationDetails() { - setKind("documentModelCompose"); + } + + /** + * Get the kind property: Type of operation. + * + * @return the kind value. + */ + @Override + public String getKind() { + return this.kind; } /** @@ -146,11 +160,11 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getLastUpdatedDateTime())); jsonWriter.writeStringField("resourceLocation", getResourceLocation()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeNumberField("percentCompleted", getPercentCompleted()); jsonWriter.writeStringField("apiVersion", getApiVersion()); jsonWriter.writeMapField("tags", getTags(), (writer, element) -> writer.writeString(element)); jsonWriter.writeJsonField("error", getError()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeJsonField("result", this.result); return jsonWriter.writeEndObject(); } @@ -184,8 +198,6 @@ public static DocumentModelComposeOperationDetails fromJson(JsonReader jsonReade reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); } else if ("resourceLocation".equals(fieldName)) { deserializedDocumentModelComposeOperationDetails.setResourceLocation(reader.getString()); - } else if ("kind".equals(fieldName)) { - deserializedDocumentModelComposeOperationDetails.setKind(reader.getString()); } else if ("percentCompleted".equals(fieldName)) { deserializedDocumentModelComposeOperationDetails .setPercentCompleted(reader.getNullable(JsonReader::getInt)); @@ -196,6 +208,8 @@ public static DocumentModelComposeOperationDetails fromJson(JsonReader jsonReade deserializedDocumentModelComposeOperationDetails.setTags(tags); } else if ("error".equals(fieldName)) { deserializedDocumentModelComposeOperationDetails.setError(Error.fromJson(reader)); + } else if ("kind".equals(fieldName)) { + deserializedDocumentModelComposeOperationDetails.kind = reader.getString(); } else if ("result".equals(fieldName)) { deserializedDocumentModelComposeOperationDetails.result = DocumentModelDetails.fromJson(reader); } else { diff --git a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelCopyToOperationDetails.java b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelCopyToOperationDetails.java index b3672009d9..5dbd6e9af4 100644 --- a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelCopyToOperationDetails.java +++ b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/DocumentModelCopyToOperationDetails.java @@ -18,6 +18,11 @@ */ @Fluent public final class DocumentModelCopyToOperationDetails extends OperationDetails { + /* + * Type of operation. + */ + private String kind = "documentModelCopyTo"; + /* * Operation result upon success. */ @@ -27,7 +32,16 @@ public final class DocumentModelCopyToOperationDetails extends OperationDetails * Creates an instance of DocumentModelCopyToOperationDetails class. */ public DocumentModelCopyToOperationDetails() { - setKind("documentModelCopyTo"); + } + + /** + * Get the kind property: Type of operation. + * + * @return the kind value. + */ + @Override + public String getKind() { + return this.kind; } /** @@ -146,11 +160,11 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getLastUpdatedDateTime())); jsonWriter.writeStringField("resourceLocation", getResourceLocation()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeNumberField("percentCompleted", getPercentCompleted()); jsonWriter.writeStringField("apiVersion", getApiVersion()); jsonWriter.writeMapField("tags", getTags(), (writer, element) -> writer.writeString(element)); jsonWriter.writeJsonField("error", getError()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeJsonField("result", this.result); return jsonWriter.writeEndObject(); } @@ -184,8 +198,6 @@ public static DocumentModelCopyToOperationDetails fromJson(JsonReader jsonReader reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); } else if ("resourceLocation".equals(fieldName)) { deserializedDocumentModelCopyToOperationDetails.setResourceLocation(reader.getString()); - } else if ("kind".equals(fieldName)) { - deserializedDocumentModelCopyToOperationDetails.setKind(reader.getString()); } else if ("percentCompleted".equals(fieldName)) { deserializedDocumentModelCopyToOperationDetails .setPercentCompleted(reader.getNullable(JsonReader::getInt)); @@ -196,6 +208,8 @@ public static DocumentModelCopyToOperationDetails fromJson(JsonReader jsonReader deserializedDocumentModelCopyToOperationDetails.setTags(tags); } else if ("error".equals(fieldName)) { deserializedDocumentModelCopyToOperationDetails.setError(Error.fromJson(reader)); + } else if ("kind".equals(fieldName)) { + deserializedDocumentModelCopyToOperationDetails.kind = reader.getString(); } else if ("result".equals(fieldName)) { deserializedDocumentModelCopyToOperationDetails.result = DocumentModelDetails.fromJson(reader); } else { diff --git a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/OperationDetails.java b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/OperationDetails.java index 451b9c2fef..5dde80124e 100644 --- a/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/OperationDetails.java +++ b/azure-dataplane-tests/src/main/java/com/azure/ai/formrecognizer/documentanalysis/implementation/models/OperationDetails.java @@ -85,17 +85,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: Type of operation. - * - * @param kind the kind value to set. - * @return the OperationDetails object itself. - */ - protected OperationDetails setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the operationId property: Operation ID. * diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Cookiecuttershark.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Cookiecuttershark.java index 45513250a3..916ae99b10 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Cookiecuttershark.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Cookiecuttershark.java @@ -18,11 +18,25 @@ */ @Fluent public final class Cookiecuttershark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "cookiecuttershark"; + /** * Creates an instance of Cookiecuttershark class. */ public Cookiecuttershark() { - setFishtype("cookiecuttershark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -79,10 +93,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); return jsonWriter.writeEndObject(); } @@ -106,8 +120,6 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti } else if ("birthday".equals(fieldName)) { deserializedCookiecuttershark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedCookiecuttershark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedCookiecuttershark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -115,6 +127,8 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti deserializedCookiecuttershark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedCookiecuttershark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedCookiecuttershark.fishtype = reader.getString(); } else { reader.skipChildren(); } diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotFish.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotFish.java index 2ca1041f1e..49fecef169 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotFish.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotFish.java @@ -42,17 +42,6 @@ public String getFishType() { return this.fishType; } - /** - * Set the fishType property: The fish.type property. - * - * @param fishType the fishType value to set. - * @return the DotFish object itself. - */ - protected DotFish setFishType(String fishType) { - this.fishType = fishType; - return this; - } - /** * Get the species property: The species property. * diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotSalmon.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotSalmon.java index c15c47deb1..ce2194521b 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotSalmon.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/DotSalmon.java @@ -17,6 +17,11 @@ */ @Fluent public final class DotSalmon extends DotFish { + /* + * The fish.type property. + */ + private String fishType = "DotSalmon"; + /* * The location property. */ @@ -32,7 +37,16 @@ public final class DotSalmon extends DotFish { * Creates an instance of DotSalmon class. */ public DotSalmon() { - setFishType("DotSalmon"); + } + + /** + * Get the fishType property: The fish.type property. + * + * @return the fishType value. + */ + @Override + public String getFishType() { + return this.fishType; } /** @@ -89,8 +103,8 @@ public DotSalmon setSpecies(String species) { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("fish.type", getFishType()); jsonWriter.writeStringField("species", getSpecies()); + jsonWriter.writeStringField("fish.type", this.fishType); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.isWild); return jsonWriter.writeEndObject(); @@ -110,10 +124,10 @@ public static DotSalmon fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fish.type".equals(fieldName)) { - deserializedDotSalmon.setFishType(reader.getString()); - } else if ("species".equals(fieldName)) { + if ("species".equals(fieldName)) { deserializedDotSalmon.setSpecies(reader.getString()); + } else if ("fish.type".equals(fieldName)) { + deserializedDotSalmon.fishType = reader.getString(); } else if ("location".equals(fieldName)) { deserializedDotSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Fish.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Fish.java index f9d67565d2..8a21a60011 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Fish.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Fish.java @@ -53,17 +53,6 @@ public String getFishtype() { return this.fishtype; } - /** - * Set the fishtype property: The fishtype property. - * - * @param fishtype the fishtype value to set. - * @return the Fish object itself. - */ - protected Fish setFishtype(String fishtype) { - this.fishtype = fishtype; - return this; - } - /** * Get the species property: The species property. * diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/GoblinShark.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/GoblinShark.java index 65f23e9485..73eadd070a 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/GoblinShark.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/GoblinShark.java @@ -18,6 +18,11 @@ */ @Fluent public final class GoblinShark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "goblin"; + /* * The jawsize property. */ @@ -32,7 +37,16 @@ public final class GoblinShark extends Shark { * Creates an instance of Goblinshark class. */ public GoblinShark() { - setFishtype("goblin"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -129,10 +143,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("jawsize", this.jawsize); jsonWriter.writeStringField("color", this.color == null ? null : this.color.toString()); return jsonWriter.writeEndObject(); @@ -158,8 +172,6 @@ public static GoblinShark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedGoblinshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedGoblinshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedGoblinshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -167,6 +179,8 @@ public static GoblinShark fromJson(JsonReader jsonReader) throws IOException { deserializedGoblinshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedGoblinshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedGoblinshark.fishtype = reader.getString(); } else if ("jawsize".equals(fieldName)) { deserializedGoblinshark.jawsize = reader.getNullable(JsonReader::getInt); } else if ("color".equals(fieldName)) { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyBaseType.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyBaseType.java index f8834cc227..855f0d4727 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyBaseType.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyBaseType.java @@ -47,17 +47,6 @@ public MyKind getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the MyBaseType object itself. - */ - protected MyBaseType setKind(MyKind kind) { - this.kind = kind; - return this; - } - /** * Get the propB1 property: The propB1 property. * diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyDerivedType.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyDerivedType.java index af8b01d82b..8582700a01 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyDerivedType.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/MyDerivedType.java @@ -15,6 +15,11 @@ */ @Fluent public final class MyDerivedType extends MyBaseType { + /* + * The kind property. + */ + private MyKind kind = MyKind.KIND1; + /* * The propD1 property. */ @@ -24,7 +29,16 @@ public final class MyDerivedType extends MyBaseType { * Creates an instance of MyDerivedType class. */ public MyDerivedType() { - setKind(MyKind.KIND1); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Override + public MyKind getKind() { + return this.kind; } /** @@ -71,8 +85,8 @@ public MyDerivedType setPropBH1(String propBH1) { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); jsonWriter.writeStringField("propB1", getPropB1()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); jsonWriter.writeStringField("propD1", this.propD1); if (getPropBH1() != null) { jsonWriter.writeStartObject("helper"); @@ -96,10 +110,10 @@ public static MyDerivedType fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { - deserializedMyDerivedType.setKind(MyKind.fromString(reader.getString())); - } else if ("propB1".equals(fieldName)) { + if ("propB1".equals(fieldName)) { deserializedMyDerivedType.setPropB1(reader.getString()); + } else if ("kind".equals(fieldName)) { + deserializedMyDerivedType.kind = MyKind.fromString(reader.getString()); } else if ("propD1".equals(fieldName)) { deserializedMyDerivedType.propD1 = reader.getString(); } else if ("helper".equals(fieldName) && reader.currentToken() == JsonToken.START_OBJECT) { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Salmon.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Salmon.java index adf5c837da..af78b2366f 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Salmon.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Salmon.java @@ -16,6 +16,11 @@ */ @Fluent public class Salmon extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "salmon"; + /* * The location property. */ @@ -30,7 +35,16 @@ public class Salmon extends Fish { * Creates an instance of Salmon class. */ public Salmon() { - setFishtype("salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -107,9 +121,9 @@ public Salmon setSiblings(List siblings) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -157,13 +171,13 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti if ("length".equals(fieldName)) { deserializedSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { List siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); deserializedSalmon.setSiblings(siblings); + } else if ("fishtype".equals(fieldName)) { + deserializedSalmon.fishtype = reader.getString(); } else if ("location".equals(fieldName)) { deserializedSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Sawshark.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Sawshark.java index ba49b91100..b97a132743 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Sawshark.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Sawshark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Sawshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "sawshark"; + /* * The picture property. */ @@ -28,7 +33,16 @@ public final class Sawshark extends Shark { * Creates an instance of Sawshark class. */ public Sawshark() { - setFishtype("sawshark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -105,10 +119,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeBinaryField("picture", this.picture); return jsonWriter.writeEndObject(); } @@ -133,8 +147,6 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedSawshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedSawshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSawshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -142,6 +154,8 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { deserializedSawshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedSawshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedSawshark.fishtype = reader.getString(); } else if ("picture".equals(fieldName)) { deserializedSawshark.picture = reader.getBinary(); } else { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Shark.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Shark.java index 9a697dffea..4f5122586a 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Shark.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/Shark.java @@ -18,6 +18,11 @@ */ @Fluent public class Shark extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "shark"; + /* * The age property. */ @@ -32,7 +37,16 @@ public class Shark extends Fish { * Creates an instance of Shark class. */ public Shark() { - setFishtype("shark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -109,11 +123,11 @@ public Shark setSiblings(List siblings) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("birthday", this.birthday == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.birthday)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("age", this.age); return jsonWriter.writeEndObject(); } @@ -164,8 +178,6 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("length".equals(fieldName)) { deserializedShark.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedShark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedShark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -174,6 +186,8 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } else if ("birthday".equals(fieldName)) { deserializedShark.birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("fishtype".equals(fieldName)) { + deserializedShark.fishtype = reader.getString(); } else if ("age".equals(fieldName)) { deserializedShark.age = reader.getNullable(JsonReader::getInt); } else { diff --git a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/SmartSalmon.java b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/SmartSalmon.java index 7d2a3ee292..d16823d70d 100644 --- a/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/SmartSalmon.java +++ b/customization-tests/src/main/java/fixtures/bodycomplex/implementation/models/SmartSalmon.java @@ -18,6 +18,11 @@ */ @Fluent public final class SmartSalmon extends Salmon { + /* + * The fishtype property. + */ + private String fishtype = "smart_salmon"; + /* * The college_degree property. */ @@ -32,7 +37,16 @@ public final class SmartSalmon extends Salmon { * Creates an instance of SmartSalmon class. */ public SmartSalmon() { - setFishtype("smart_salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -127,11 +141,11 @@ public SmartSalmon setSiblings(List siblings) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("location", getLocation()); jsonWriter.writeBooleanField("iswild", iswild()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("college_degree", this.collegeDegree); if (additionalProperties != null) { for (Map.Entry additionalProperty : additionalProperties.entrySet()) { @@ -159,8 +173,6 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { if ("length".equals(fieldName)) { deserializedSmartSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSmartSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSmartSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -170,6 +182,8 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { deserializedSmartSalmon.setLocation(reader.getString()); } else if ("iswild".equals(fieldName)) { deserializedSmartSalmon.setIswild(reader.getNullable(JsonReader::getBoolean)); + } else if ("fishtype".equals(fieldName)) { + deserializedSmartSalmon.fishtype = reader.getString(); } else if ("college_degree".equals(fieldName)) { deserializedSmartSalmon.collegeDegree = reader.getString(); } else { diff --git a/javagen/src/main/java/com/azure/autorest/implementation/ClientModelPropertiesManager.java b/javagen/src/main/java/com/azure/autorest/implementation/ClientModelPropertiesManager.java index f82d60d8f9..8e23bc91c4 100644 --- a/javagen/src/main/java/com/azure/autorest/implementation/ClientModelPropertiesManager.java +++ b/javagen/src/main/java/com/azure/autorest/implementation/ClientModelPropertiesManager.java @@ -136,9 +136,11 @@ public ClientModelPropertiesManager(ClientModel model, JavaSettings settings) { discriminatorProperty = new ClientModelPropertyWithMetadata(model, property, true); } - superPropertyConsumer(property, superRequiredProperties, superConstructorProperties, - superReadOnlyProperties, superSetterProperties, settings); - hasRequiredProperties |= property.isRequired(); + if (!property.isPolymorphicDiscriminator()) { + superPropertyConsumer(property, superRequiredProperties, superConstructorProperties, + superReadOnlyProperties, superSetterProperties, settings); + hasRequiredProperties |= property.isRequired(); + } if (property.getNeedsFlatten()) { flattenedProperties.put(property.getName(), new ClientModelPropertyWithMetadata(model, property, true)); @@ -170,14 +172,7 @@ public ClientModelPropertiesManager(ClientModel model, JavaSettings settings) { readOnlyProperties = new LinkedHashMap<>(); ClientModelProperty additionalProperties = null; for (ClientModelProperty property : model.getProperties()) { - if (property.isPolymorphicDiscriminator() && discriminatorProperty != null - && Objects.equals(discriminatorProperty.getProperty().getSerializedName(), property.getSerializedName())) { - // The super type has defined the discriminator property, don't include it in the models properties - // but override the property it's pointing to in the super properties. Overriding is needed to ensure - // the correct default value is used. - superPropertyConsumer(property, superRequiredProperties, superConstructorProperties, - superReadOnlyProperties, superSetterProperties, settings); - } else if (property.isRequired()) { + if (property.isRequired()) { hasRequiredProperties = true; requiredProperties.put(property.getSerializedName(), property); diff --git a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java index 0c271fcadd..2c77ba150b 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ModelTemplate.java @@ -27,7 +27,6 @@ import com.azure.autorest.model.javamodel.JavaVisibility; import com.azure.autorest.template.util.ModelTemplateHeaderHelper; import com.azure.autorest.util.ClientModelUtil; -import com.azure.autorest.util.CodeNamer; import com.azure.autorest.util.TemplateUtil; import com.azure.core.http.HttpHeader; import com.azure.core.util.CoreUtils; @@ -168,23 +167,24 @@ public final void write(ClientModel model, JavaFile javaFile) { ? JavaVisibility.Private : JavaVisibility.Public; - if (!property.isPolymorphicDiscriminator() || modelDefinesProperty(model, property)) { - // Only the super most parent model should have the polymorphic discriminator getter. - // The child models should use the parent's getter. - generateGetterJavadoc(classBlock, model, property); - addGeneratedAnnotation(classBlock); - if (property.isAdditionalProperties() && !settings.isStreamStyleSerialization()) { - classBlock.annotation("JsonAnyGetter"); - } - if (!propertyIsReadOnly) { - TemplateUtil.addJsonGetter(classBlock, settings, property.getSerializedName()); - } + generateGetterJavadoc(classBlock, model, property); + addGeneratedAnnotation(classBlock); + if (property.isAdditionalProperties() && !settings.isStreamStyleSerialization()) { + classBlock.annotation("JsonAnyGetter"); + } + if (!propertyIsReadOnly) { + TemplateUtil.addJsonGetter(classBlock, settings, property.getSerializedName()); + } - classBlock.method(methodVisibility, null, - propertyClientType + " " + getGetterName(model, property) + "()", - methodBlock -> addGetterMethod(propertyWireType, propertyClientType, property, treatAsXml, - methodBlock, settings)); + // getter method of discriminator property in subclass is handled differently + final boolean polymorphicDiscriminatorInSubclass = property.isPolymorphicDiscriminator() && !modelDefinesProperty(model, property); + if (polymorphicDiscriminatorInSubclass) { + classBlock.annotation("Override"); } + classBlock.method(methodVisibility, null, + propertyClientType + " " + getGetterName(model, property) + "()", + methodBlock -> addGetterMethod(propertyWireType, propertyClientType, property, treatAsXml, + methodBlock, settings)); // The model is immutable output only if and only if the immutable output model setting is enabled and // the usage of the model include output and does not include input. @@ -214,10 +214,8 @@ public final void write(ClientModel model, JavaFile javaFile) { settings); boolean definedByModel = modelDefinesProperty(model, property); if (hasDerivedTypes && notIncludedInConstructor && definedByModel - && (settings.isStreamStyleSerialization() || property.isPolymorphicDiscriminator())) { - // Super class and child classes may be in different packages. - // Since we call polymorphic setter in child classes' constructor, we need the setter to be visibility of protected. - methodVisibility = property.isPolymorphicDiscriminator() ? JavaVisibility.Protected : JavaVisibility.PackagePrivate; + && streamStyle && !property.isPolymorphicDiscriminator()) { + methodVisibility = JavaVisibility.PackagePrivate; generateSetterJavadoc(classBlock, model, property); addGeneratedAnnotation(classBlock); classBlock.method(methodVisibility, null, @@ -541,12 +539,12 @@ protected void addXmlNamespaceConstants(ClientModel model, JavaClass classBlock) */ private void addProperties(ClientModel model, JavaClass classBlock, JavaSettings settings) { for (ClientModelProperty property : model.getProperties()) { - if (property.isPolymorphicDiscriminator() && !modelDefinesProperty(model, property)) { - // Only the super most parent model should have the polymorphic discriminator as a field. - // The child models should use the parent's field. If the polymorphic property is required, it will be - // initialized in the parent's constructor. Otherwise, it will be set using the package-private setter. - continue; - } +// if (property.isPolymorphicDiscriminator() && !modelDefinesProperty(model, property)) { +// // Only the super most parent model should have the polymorphic discriminator as a field. +// // The child models should use the parent's field. If the polymorphic property is required, it will be +// // initialized in the parent's constructor. Otherwise, it will be set using the package-private setter. +// continue; +// } String propertyName = property.getName(); IType propertyType = property.getWireType(); @@ -572,11 +570,7 @@ private void addProperties(ClientModel model, JavaClass classBlock, JavaSettings // required, in which case the default value will be set in the constructor. if (property.getDefaultValue() != null && (!ClientModelUtil.includePropertyInConstructor(property, settings) || property.isConstant())) { - if (property.isPolymorphicDiscriminator() && !settings.isStreamStyleSerialization()) { - fieldSignature = propertyType + " " + CodeNamer.getEnumMemberName(propertyName) + " = " + property.getDefaultValue(); - } else { - fieldSignature = propertyType + " " + propertyName + " = " + property.getDefaultValue(); - } + fieldSignature = propertyType + " " + propertyName + " = " + property.getDefaultValue(); } else { fieldSignature = propertyType + " " + propertyName; } @@ -592,11 +586,7 @@ private void addProperties(ClientModel model, JavaClass classBlock, JavaSettings // required, in which case the default value will be set in the constructor. if (property.getDefaultValue() != null && (!ClientModelUtil.includePropertyInConstructor(property, settings) || property.isConstant())) { - if (property.isPolymorphicDiscriminator() && !settings.isStreamStyleSerialization()) { - fieldSignature = propertyType + " " + CodeNamer.getEnumMemberName(propertyName) + " = " + property.getDefaultValue(); - } else { - fieldSignature = propertyType + " " + propertyName + " = " + property.getDefaultValue(); - } + fieldSignature = propertyType + " " + propertyName + " = " + property.getDefaultValue(); } else { fieldSignature = propertyType + " " + propertyName; } @@ -829,9 +819,10 @@ private void addModelConstructor(ClientModel model, JavaVisibility constructorVi if (modelDefinesProperty(model, polymorphicProperty)) { constructor.line("this." + polymorphicProperty.getName() + " = " + discriminatorValue + ";"); - } else { - constructor.line(polymorphicProperty.getSetterName() + "(" + discriminatorValue + ");"); } +// else { +// constructor.line(polymorphicProperty.getSetterName() + "(" + discriminatorValue + ");"); +// } } // constant properties should already be initialized in class variable definition @@ -938,6 +929,7 @@ private static void addModelConstructorParameterAsWireType( * @param property The property. * @param treatAsXml Whether the getter should treat the property as XML. * @param methodBlock Where the getter method is being added. + * @param settings Java settings. */ private static void addGetterMethod(IType propertyWireType, IType propertyClientType, ClientModelProperty property, boolean treatAsXml, JavaBlock methodBlock, JavaSettings settings) { diff --git a/typespec-tests/Generate.ps1 b/typespec-tests/Generate.ps1 index b9646fc8e1..f8eb3368e6 100644 --- a/typespec-tests/Generate.ps1 +++ b/typespec-tests/Generate.ps1 @@ -56,6 +56,9 @@ $generateScript = { $tspOptions += " --option ""@azure-tools/typespec-java.customization-class=../../customization/src/main/java/CustomizationTest.java""" } elseif ($tspFile -match "encode[\\/]bytes[\\/]main.tsp") { $tspOptions += " --option ""@azure-tools/typespec-java.customization-class=../../customization/src/main/java/CustomizationEncodeBytes.java""" + } elseif ($tspFile -match "type[\\/]model[\\/]inheritance[\\/]nested-discriminator[\\/]main.tsp") { + # nested discriminator is not supported + $tspOptions += " --option ""@azure-tools/typespec-java.customization-class=../../customization/src/main/java/CustomizationNestedDiscriminator.java""" } $tspTrace = "--trace import-resolution --trace projection --trace typespec-java" diff --git a/typespec-tests/customization/src/main/java/CustomizationEncodeBytes.java b/typespec-tests/customization/src/main/java/CustomizationEncodeBytes.java index 77f258c7cb..d11338b556 100644 --- a/typespec-tests/customization/src/main/java/CustomizationEncodeBytes.java +++ b/typespec-tests/customization/src/main/java/CustomizationEncodeBytes.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. import com.azure.autorest.customization.ClassCustomization; -import com.azure.autorest.customization.ConstructorCustomization; import com.azure.autorest.customization.Customization; import com.azure.autorest.customization.LibraryCustomization; import com.azure.autorest.customization.PackageCustomization; diff --git a/typespec-tests/customization/src/main/java/CustomizationNestedDiscriminator.java b/typespec-tests/customization/src/main/java/CustomizationNestedDiscriminator.java new file mode 100644 index 0000000000..0e46f91bf9 --- /dev/null +++ b/typespec-tests/customization/src/main/java/CustomizationNestedDiscriminator.java @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import com.azure.autorest.customization.ClassCustomization; +import com.azure.autorest.customization.ConstructorCustomization; +import com.azure.autorest.customization.Customization; +import com.azure.autorest.customization.LibraryCustomization; +import com.azure.autorest.customization.PackageCustomization; +import org.slf4j.Logger; + +/** + * This class contains the customization code to customize the AutoRest generated code for App Configuration. + */ +public class CustomizationNestedDiscriminator extends Customization { + + @Override + public void customize(LibraryCustomization customization, Logger logger) { + logger.info("Customizing the Base64urlArrayBytesProperty"); + + PackageCustomization packageCustomization = customization.getPackage("com.type.model.inheritance.nesteddiscriminator.models"); + ClassCustomization classCustomization = packageCustomization.getClass("GoblinShark"); + + ConstructorCustomization constructorCustomization = classCustomization.getConstructor("GoblinShark"); + constructorCustomization.replaceBody("super(age, sharktype); this.sharktype = \"goblin\";"); + + classCustomization = packageCustomization.getClass("SawShark"); + + constructorCustomization = classCustomization.getConstructor("SawShark"); + constructorCustomization.replaceBody("super(age, sharktype); this.sharktype = \"saw\";"); + } +} diff --git a/typespec-tests/customization/src/main/java/CustomizationTest.java b/typespec-tests/customization/src/main/java/CustomizationTest.java index dbef6dd6ce..b3951472d3 100644 --- a/typespec-tests/customization/src/main/java/CustomizationTest.java +++ b/typespec-tests/customization/src/main/java/CustomizationTest.java @@ -2,11 +2,6 @@ import com.azure.autorest.customization.Customization; import com.azure.autorest.customization.LibraryCustomization; import com.azure.autorest.customization.PackageCustomization; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.stmt.BlockStmt; import org.slf4j.Logger; import java.util.Arrays; diff --git a/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/AbstractModel.java b/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/AbstractModel.java index 06c53c8b31..c4bc41446e 100644 --- a/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/AbstractModel.java +++ b/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/AbstractModel.java @@ -50,18 +50,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the AbstractModel object itself. - */ - @Generated - protected AbstractModel setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the name property: The name property. * diff --git a/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/RealModel.java b/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/RealModel.java index 7e78466eab..b7ddb2eb75 100644 --- a/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/RealModel.java +++ b/typespec-tests/src/main/java/com/_specs_/azure/clientgenerator/core/access/implementation/models/RealModel.java @@ -16,6 +16,12 @@ */ @Immutable public final class RealModel extends AbstractModel { + /* + * The kind property. + */ + @Generated + private String kind = "real"; + /** * Creates an instance of RealModel class. * @@ -24,7 +30,17 @@ public final class RealModel extends AbstractModel { @Generated private RealModel(String name) { super(name); - setKind("real"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ private RealModel(String name) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", getName()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static RealModel fromJson(JsonReader jsonReader) throws IOException { } } RealModel deserializedRealModel = new RealModel(name); - deserializedRealModel.setKind(kind); + deserializedRealModel.kind = kind; return deserializedRealModel; }); diff --git a/typespec-tests/src/main/java/com/cadl/naming/models/BytesData.java b/typespec-tests/src/main/java/com/cadl/naming/models/BytesData.java index 1ecbbb946d..108e509f64 100644 --- a/typespec-tests/src/main/java/com/cadl/naming/models/BytesData.java +++ b/typespec-tests/src/main/java/com/cadl/naming/models/BytesData.java @@ -17,6 +17,12 @@ */ @Immutable public final class BytesData extends Data { + /* + * The @data.kind property. + */ + @Generated + private String type = "bytes"; + /* * Data as {@code byte[]} */ @@ -30,10 +36,20 @@ public final class BytesData extends Data { */ @Generated private BytesData(byte[] dataAsBytes) { - setType("bytes"); this.dataAsBytes = dataAsBytes; } + /** + * Get the type property: The @data.kind property. + * + * @return the type value. + */ + @Generated + @Override + public String getType() { + return this.type; + } + /** * Get the dataAsBytes property: Data as {@code byte[]}. * @@ -51,8 +67,8 @@ public byte[] getDataAsBytes() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("@data.kind", getType()); jsonWriter.writeBinaryField("data_bytes", this.dataAsBytes); + jsonWriter.writeStringField("@data.kind", this.type); return jsonWriter.writeEndObject(); } @@ -67,22 +83,22 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static BytesData fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - String type = "bytes"; byte[] dataAsBytes = null; + String type = "bytes"; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("@data.kind".equals(fieldName)) { - type = reader.getString(); - } else if ("data_bytes".equals(fieldName)) { + if ("data_bytes".equals(fieldName)) { dataAsBytes = reader.getBinary(); + } else if ("@data.kind".equals(fieldName)) { + type = reader.getString(); } else { reader.skipChildren(); } } BytesData deserializedBytesData = new BytesData(dataAsBytes); - deserializedBytesData.setType(type); + deserializedBytesData.type = type; return deserializedBytesData; }); diff --git a/typespec-tests/src/main/java/com/cadl/naming/models/Data.java b/typespec-tests/src/main/java/com/cadl/naming/models/Data.java index 4fe50bc5e0..8bb5e7af12 100644 --- a/typespec-tests/src/main/java/com/cadl/naming/models/Data.java +++ b/typespec-tests/src/main/java/com/cadl/naming/models/Data.java @@ -41,18 +41,6 @@ public String getType() { return this.type; } - /** - * Set the type property: The @data.kind property. - * - * @param type the type value to set. - * @return the Data object itself. - */ - @Generated - protected Data setType(String type) { - this.type = type; - return this; - } - /** * {@inheritDoc} */ diff --git a/typespec-tests/src/main/java/com/cadl/patch/models/Fish.java b/typespec-tests/src/main/java/com/cadl/patch/models/Fish.java index 16944065a5..cd14b8d6eb 100644 --- a/typespec-tests/src/main/java/com/cadl/patch/models/Fish.java +++ b/typespec-tests/src/main/java/com/cadl/patch/models/Fish.java @@ -89,19 +89,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the Fish object itself. - */ - @Generated - protected Fish setKind(String kind) { - this.kind = kind; - this.updatedProperties.add("kind"); - return this; - } - /** * Get the id property: The id property. * diff --git a/typespec-tests/src/main/java/com/cadl/patch/models/Salmon.java b/typespec-tests/src/main/java/com/cadl/patch/models/Salmon.java index 78c95c9649..ffcbfcef67 100644 --- a/typespec-tests/src/main/java/com/cadl/patch/models/Salmon.java +++ b/typespec-tests/src/main/java/com/cadl/patch/models/Salmon.java @@ -21,6 +21,12 @@ */ @Fluent public final class Salmon extends Fish { + /* + * The kind property. + */ + @Generated + private String kind = "salmon"; + /* * The friends property. */ @@ -65,7 +71,17 @@ void serializeAsJsonMergePatch(boolean jsonMergePatch) { */ @Generated public Salmon() { - setKind("salmon"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -169,9 +185,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { return toJsonMergePatch(jsonWriter); } else { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeIntField("age", getAge()); jsonWriter.writeStringField("color", getColor()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeArrayField("friends", this.friends, (writer, element) -> writer.writeJson(element)); jsonWriter.writeMapField("hate", this.hate, (writer, element) -> writer.writeJson(element)); jsonWriter.writeJsonField("partner", this.partner); @@ -182,13 +198,6 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - if (updatedProperties.contains("kind")) { - if (getKind() == null) { - jsonWriter.writeNullField("kind"); - } else { - jsonWriter.writeStringField("kind", getKind()); - } - } jsonWriter.writeIntField("age", getAge()); if (updatedProperties.contains("color")) { if (getColor() == null) { @@ -197,6 +206,13 @@ private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("color", getColor()); } } + if (updatedProperties.contains("kind")) { + if (this.kind == null) { + jsonWriter.writeNullField("kind"); + } else { + jsonWriter.writeStringField("kind", this.kind); + } + } if (updatedProperties.contains("friends")) { if (this.friends == null) { jsonWriter.writeNullField("friends"); @@ -244,9 +260,9 @@ public static Salmon fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { String id = null; String name = null; - String kind = "salmon"; int age = 0; String color = null; + String kind = "salmon"; List friends = null; Map hate = null; Fish partner = null; @@ -258,12 +274,12 @@ public static Salmon fromJson(JsonReader jsonReader) throws IOException { id = reader.getString(); } else if ("name".equals(fieldName)) { name = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getInt(); } else if ("color".equals(fieldName)) { color = reader.getString(); + } else if ("kind".equals(fieldName)) { + kind = reader.getString(); } else if ("friends".equals(fieldName)) { friends = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("hate".equals(fieldName)) { @@ -277,9 +293,9 @@ public static Salmon fromJson(JsonReader jsonReader) throws IOException { Salmon deserializedSalmon = new Salmon(); deserializedSalmon.setId(id); deserializedSalmon.setName(name); - deserializedSalmon.setKind(kind); deserializedSalmon.setAge(age); deserializedSalmon.setColor(color); + deserializedSalmon.kind = kind; deserializedSalmon.friends = friends; deserializedSalmon.hate = hate; deserializedSalmon.partner = partner; diff --git a/typespec-tests/src/main/java/com/cadl/patch/models/Shark.java b/typespec-tests/src/main/java/com/cadl/patch/models/Shark.java index 6e92bfb657..59fd91ad74 100644 --- a/typespec-tests/src/main/java/com/cadl/patch/models/Shark.java +++ b/typespec-tests/src/main/java/com/cadl/patch/models/Shark.java @@ -19,6 +19,12 @@ */ @Fluent public final class Shark extends Fish { + /* + * The kind property. + */ + @Generated + private String kind = "shark"; + @Generated private boolean jsonMergePatch; @@ -45,7 +51,17 @@ void serializeAsJsonMergePatch(boolean jsonMergePatch) { */ @Generated public Shark() { - setKind("shark"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -80,9 +96,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { return toJsonMergePatch(jsonWriter); } else { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeIntField("age", getAge()); jsonWriter.writeStringField("color", getColor()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } } @@ -90,13 +106,6 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - if (updatedProperties.contains("kind")) { - if (getKind() == null) { - jsonWriter.writeNullField("kind"); - } else { - jsonWriter.writeStringField("kind", getKind()); - } - } jsonWriter.writeIntField("age", getAge()); if (updatedProperties.contains("color")) { if (getColor() == null) { @@ -105,6 +114,13 @@ private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("color", getColor()); } } + if (updatedProperties.contains("kind")) { + if (this.kind == null) { + jsonWriter.writeNullField("kind"); + } else { + jsonWriter.writeStringField("kind", this.kind); + } + } return jsonWriter.writeEndObject(); } @@ -121,9 +137,9 @@ public static Shark fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { String id = null; String name = null; - String kind = "shark"; int age = 0; String color = null; + String kind = "shark"; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -132,12 +148,12 @@ public static Shark fromJson(JsonReader jsonReader) throws IOException { id = reader.getString(); } else if ("name".equals(fieldName)) { name = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getInt(); } else if ("color".equals(fieldName)) { color = reader.getString(); + } else if ("kind".equals(fieldName)) { + kind = reader.getString(); } else { reader.skipChildren(); } @@ -145,9 +161,9 @@ public static Shark fromJson(JsonReader jsonReader) throws IOException { Shark deserializedShark = new Shark(); deserializedShark.setId(id); deserializedShark.setName(name); - deserializedShark.setKind(kind); deserializedShark.setAge(age); deserializedShark.setColor(color); + deserializedShark.kind = kind; return deserializedShark; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Cobra.java b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Cobra.java index e86c39e593..b10e507640 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Cobra.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Cobra.java @@ -16,6 +16,12 @@ */ @Immutable public final class Cobra extends Snake { + /* + * discriminator property + */ + @Generated + private SnakeKind kind = SnakeKind.COBRA; + /** * Creates an instance of Cobra class. * @@ -24,7 +30,17 @@ public final class Cobra extends Snake { @Generated public Cobra(int length) { super(length); - setKind(SnakeKind.COBRA); + } + + /** + * Get the kind property: discriminator property. + * + * @return the kind value. + */ + @Generated + @Override + public SnakeKind getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ public Cobra(int length) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("length", getLength()); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static Cobra fromJson(JsonReader jsonReader) throws IOException { } } Cobra deserializedCobra = new Cobra(length); - deserializedCobra.setKind(kind); + deserializedCobra.kind = kind; return deserializedCobra; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Dog.java b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Dog.java index 189e8d1121..daa740ef9c 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Dog.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Dog.java @@ -50,18 +50,6 @@ public DogKind getKind() { return this.kind; } - /** - * Set the kind property: discriminator property. - * - * @param kind the kind value to set. - * @return the Dog object itself. - */ - @Generated - protected Dog setKind(DogKind kind) { - this.kind = kind; - return this; - } - /** * Get the weight property: Weight of the dog. * diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Golden.java b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Golden.java index ee35e76c58..1a4f412be5 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Golden.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Golden.java @@ -16,6 +16,12 @@ */ @Immutable public final class Golden extends Dog { + /* + * discriminator property + */ + @Generated + private DogKind kind = DogKind.GOLDEN; + /** * Creates an instance of Golden class. * @@ -24,7 +30,17 @@ public final class Golden extends Dog { @Generated public Golden(int weight) { super(weight); - setKind(DogKind.GOLDEN); + } + + /** + * Get the kind property: discriminator property. + * + * @return the kind value. + */ + @Generated + @Override + public DogKind getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ public Golden(int weight) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("weight", getWeight()); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static Golden fromJson(JsonReader jsonReader) throws IOException { } } Golden deserializedGolden = new Golden(weight); - deserializedGolden.setKind(kind); + deserializedGolden.kind = kind; return deserializedGolden; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java index ef443141d6..58af7e82b7 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/enumdiscriminator/models/Snake.java @@ -50,18 +50,6 @@ public SnakeKind getKind() { return this.kind; } - /** - * Set the kind property: discriminator property. - * - * @param kind the kind value to set. - * @return the Snake object itself. - */ - @Generated - protected Snake setKind(SnakeKind kind) { - this.kind = kind; - return this; - } - /** * Get the length property: Length of the snake. * diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Fish.java b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Fish.java index 56cccbda9a..4cce285173 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Fish.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Fish.java @@ -50,18 +50,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the Fish object itself. - */ - @Generated - protected Fish setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the age property: The age property. * diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/GoblinShark.java b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/GoblinShark.java index 73ae2c2e76..02137ea49d 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/GoblinShark.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/GoblinShark.java @@ -16,6 +16,12 @@ */ @Immutable public final class GoblinShark extends Shark { + /* + * The sharktype property. + */ + @Generated + private final String sharktype; + /** * Creates an instance of GoblinShark class. * @@ -25,6 +31,18 @@ public final class GoblinShark extends Shark { @Generated public GoblinShark(int age, String sharktype) { super(age, sharktype); + this.sharktype = "goblin"; + } + + /** + * Get the sharktype property: The sharktype property. + * + * @return the sharktype value. + */ + @Generated + @Override + public String getSharktype() { + return this.sharktype; } /** @@ -35,8 +53,7 @@ public GoblinShark(int age, String sharktype) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("age", getAge()); - jsonWriter.writeStringField("sharktype", getSharktype()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("sharktype", this.sharktype); return jsonWriter.writeEndObject(); } @@ -53,7 +70,6 @@ public static GoblinShark fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { int age = 0; String sharktype = "goblin"; - String kind = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -62,16 +78,11 @@ public static GoblinShark fromJson(JsonReader jsonReader) throws IOException { age = reader.getInt(); } else if ("sharktype".equals(fieldName)) { sharktype = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else { reader.skipChildren(); } } - GoblinShark deserializedGoblinShark = new GoblinShark(age, sharktype); - deserializedGoblinShark.setKind(kind); - - return deserializedGoblinShark; + return new GoblinShark(age, sharktype); }); } } diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Salmon.java b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Salmon.java index 1455b07147..67c97ab0ab 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Salmon.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Salmon.java @@ -18,6 +18,12 @@ */ @Fluent public final class Salmon extends Fish { + /* + * The kind property. + */ + @Generated + private String kind = "salmon"; + /* * The friends property. */ @@ -44,7 +50,17 @@ public final class Salmon extends Fish { @Generated public Salmon(int age) { super(age); - setKind("salmon"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -121,7 +137,7 @@ public Salmon setPartner(Fish partner) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("age", getAge()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeArrayField("friends", this.friends, (writer, element) -> writer.writeJson(element)); jsonWriter.writeMapField("hate", this.hate, (writer, element) -> writer.writeJson(element)); jsonWriter.writeJsonField("partner", this.partner); @@ -163,7 +179,7 @@ public static Salmon fromJson(JsonReader jsonReader) throws IOException { } } Salmon deserializedSalmon = new Salmon(age); - deserializedSalmon.setKind(kind); + deserializedSalmon.kind = kind; deserializedSalmon.friends = friends; deserializedSalmon.hate = hate; deserializedSalmon.partner = partner; diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/SawShark.java b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/SawShark.java index 030cd4eda7..ddd2bfa5e8 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/SawShark.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/SawShark.java @@ -16,6 +16,12 @@ */ @Immutable public final class SawShark extends Shark { + /* + * The sharktype property. + */ + @Generated + private final String sharktype; + /** * Creates an instance of SawShark class. * @@ -25,6 +31,18 @@ public final class SawShark extends Shark { @Generated public SawShark(int age, String sharktype) { super(age, sharktype); + this.sharktype = "saw"; + } + + /** + * Get the sharktype property: The sharktype property. + * + * @return the sharktype value. + */ + @Generated + @Override + public String getSharktype() { + return this.sharktype; } /** @@ -35,8 +53,7 @@ public SawShark(int age, String sharktype) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("age", getAge()); - jsonWriter.writeStringField("sharktype", getSharktype()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("sharktype", this.sharktype); return jsonWriter.writeEndObject(); } @@ -53,7 +70,6 @@ public static SawShark fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { int age = 0; String sharktype = "saw"; - String kind = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -62,16 +78,11 @@ public static SawShark fromJson(JsonReader jsonReader) throws IOException { age = reader.getInt(); } else if ("sharktype".equals(fieldName)) { sharktype = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else { reader.skipChildren(); } } - SawShark deserializedSawShark = new SawShark(age, sharktype); - deserializedSawShark.setKind(kind); - - return deserializedSawShark; + return new SawShark(age, sharktype); }); } } diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Shark.java b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Shark.java index bd45e313ee..aad4d01816 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Shark.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/nesteddiscriminator/models/Shark.java @@ -52,7 +52,6 @@ public String getSharktype() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("age", getAge()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeStringField("sharktype", this.sharktype); return jsonWriter.writeEndObject(); } @@ -97,7 +96,6 @@ public static Shark fromJson(JsonReader jsonReader) throws IOException { static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { int age = 0; - String kind = null; String sharktype = "shark"; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -105,18 +103,13 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("age".equals(fieldName)) { age = reader.getInt(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else if ("sharktype".equals(fieldName)) { sharktype = reader.getString(); } else { reader.skipChildren(); } } - Shark deserializedShark = new Shark(age, sharktype); - deserializedShark.setKind(kind); - - return deserializedShark; + return new Shark(age, sharktype); }); } } diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Bird.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Bird.java index 3e70d5522c..56587baf5b 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Bird.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Bird.java @@ -50,18 +50,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the Bird object itself. - */ - @Generated - protected Bird setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the wingspan property: The wingspan property. * diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Dinosaur.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Dinosaur.java index 2c90378761..9ff5cc0824 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Dinosaur.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Dinosaur.java @@ -50,18 +50,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the Dinosaur object itself. - */ - @Generated - protected Dinosaur setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the size property: The size property. * diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Eagle.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Eagle.java index c9f1148663..ed8a5ab0ef 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Eagle.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Eagle.java @@ -18,6 +18,12 @@ */ @Fluent public final class Eagle extends Bird { + /* + * The kind property. + */ + @Generated + private String kind = "eagle"; + /* * The friends property. */ @@ -44,7 +50,17 @@ public final class Eagle extends Bird { @Generated public Eagle(int wingspan) { super(wingspan); - setKind("eagle"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -121,7 +137,7 @@ public Eagle setPartner(Bird partner) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("wingspan", getWingspan()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeArrayField("friends", this.friends, (writer, element) -> writer.writeJson(element)); jsonWriter.writeMapField("hate", this.hate, (writer, element) -> writer.writeJson(element)); jsonWriter.writeJsonField("partner", this.partner); @@ -163,7 +179,7 @@ public static Eagle fromJson(JsonReader jsonReader) throws IOException { } } Eagle deserializedEagle = new Eagle(wingspan); - deserializedEagle.setKind(kind); + deserializedEagle.kind = kind; deserializedEagle.friends = friends; deserializedEagle.hate = hate; deserializedEagle.partner = partner; diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Goose.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Goose.java index ffe02bf399..c6a55fdfee 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Goose.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Goose.java @@ -16,6 +16,12 @@ */ @Immutable public final class Goose extends Bird { + /* + * The kind property. + */ + @Generated + private String kind = "goose"; + /** * Creates an instance of Goose class. * @@ -24,7 +30,17 @@ public final class Goose extends Bird { @Generated public Goose(int wingspan) { super(wingspan); - setKind("goose"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ public Goose(int wingspan) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("wingspan", getWingspan()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static Goose fromJson(JsonReader jsonReader) throws IOException { } } Goose deserializedGoose = new Goose(wingspan); - deserializedGoose.setKind(kind); + deserializedGoose.kind = kind; return deserializedGoose; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/SeaGull.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/SeaGull.java index 37b118a705..08f8c657b1 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/SeaGull.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/SeaGull.java @@ -16,6 +16,12 @@ */ @Immutable public final class SeaGull extends Bird { + /* + * The kind property. + */ + @Generated + private String kind = "seagull"; + /** * Creates an instance of SeaGull class. * @@ -24,7 +30,17 @@ public final class SeaGull extends Bird { @Generated public SeaGull(int wingspan) { super(wingspan); - setKind("seagull"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ public SeaGull(int wingspan) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("wingspan", getWingspan()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static SeaGull fromJson(JsonReader jsonReader) throws IOException { } } SeaGull deserializedSeaGull = new SeaGull(wingspan); - deserializedSeaGull.setKind(kind); + deserializedSeaGull.kind = kind; return deserializedSeaGull; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Sparrow.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Sparrow.java index df7ad8faad..532ff7389f 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Sparrow.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/Sparrow.java @@ -16,6 +16,12 @@ */ @Immutable public final class Sparrow extends Bird { + /* + * The kind property. + */ + @Generated + private String kind = "sparrow"; + /** * Creates an instance of Sparrow class. * @@ -24,7 +30,17 @@ public final class Sparrow extends Bird { @Generated public Sparrow(int wingspan) { super(wingspan); - setKind("sparrow"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ public Sparrow(int wingspan) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("wingspan", getWingspan()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static Sparrow fromJson(JsonReader jsonReader) throws IOException { } } Sparrow deserializedSparrow = new Sparrow(wingspan); - deserializedSparrow.setKind(kind); + deserializedSparrow.kind = kind; return deserializedSparrow; }); diff --git a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/TRex.java b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/TRex.java index fb616d214d..c0f3f48600 100644 --- a/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/TRex.java +++ b/typespec-tests/src/main/java/com/type/model/inheritance/singlediscriminator/models/TRex.java @@ -16,6 +16,12 @@ */ @Immutable public final class TRex extends Dinosaur { + /* + * The kind property. + */ + @Generated + private String kind = "t-rex"; + /** * Creates an instance of TRex class. * @@ -24,7 +30,17 @@ public final class TRex extends Dinosaur { @Generated private TRex(int size) { super(size); - setKind("t-rex"); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; } /** @@ -35,7 +51,7 @@ private TRex(int size) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("size", getSize()); - jsonWriter.writeStringField("kind", getKind()); + jsonWriter.writeStringField("kind", this.kind); return jsonWriter.writeEndObject(); } @@ -65,7 +81,7 @@ public static TRex fromJson(JsonReader jsonReader) throws IOException { } } TRex deserializedTRex = new TRex(size); - deserializedTRex.setKind(kind); + deserializedTRex.kind = kind; return deserializedTRex; }); diff --git a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminated.java b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminated.java index 1f2420e765..d24268ef48 100644 --- a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminated.java +++ b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminated.java @@ -59,18 +59,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The discriminator. - * - * @param kind the kind value to set. - * @return the ExtendsUnknownAdditionalPropertiesDiscriminated object itself. - */ - @Generated - protected ExtendsUnknownAdditionalPropertiesDiscriminated setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the name property: The name property. * diff --git a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminatedDerived.java b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminatedDerived.java index 9ca9a0e98a..a8806f2351 100644 --- a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminatedDerived.java +++ b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/ExtendsUnknownAdditionalPropertiesDiscriminatedDerived.java @@ -19,6 +19,12 @@ @Fluent public final class ExtendsUnknownAdditionalPropertiesDiscriminatedDerived extends ExtendsUnknownAdditionalPropertiesDiscriminated { + /* + * The discriminator + */ + @Generated + private String kind = "derived"; + /* * The index property */ @@ -40,10 +46,20 @@ public final class ExtendsUnknownAdditionalPropertiesDiscriminatedDerived @Generated public ExtendsUnknownAdditionalPropertiesDiscriminatedDerived(String name, int index) { super(name); - setKind("derived"); this.index = index; } + /** + * Get the kind property: The discriminator. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; + } + /** * Get the index property: The index property. * @@ -84,8 +100,8 @@ public ExtendsUnknownAdditionalPropertiesDiscriminatedDerived setAge(Double age) public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", getName()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeIntField("index", this.index); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeNumberField("age", this.age); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -108,8 +124,8 @@ public static ExtendsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(Js throws IOException { return jsonReader.readObject(reader -> { String name = null; - String kind = "derived"; int index = 0; + String kind = "derived"; Double age = null; Map additionalProperties = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -118,10 +134,10 @@ public static ExtendsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(Js if ("name".equals(fieldName)) { name = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else if ("index".equals(fieldName)) { index = reader.getInt(); + } else if ("kind".equals(fieldName)) { + kind = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getDouble); } else { @@ -134,7 +150,7 @@ public static ExtendsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(Js } ExtendsUnknownAdditionalPropertiesDiscriminatedDerived deserializedExtendsUnknownAdditionalPropertiesDiscriminatedDerived = new ExtendsUnknownAdditionalPropertiesDiscriminatedDerived(name, index); - deserializedExtendsUnknownAdditionalPropertiesDiscriminatedDerived.setKind(kind); + deserializedExtendsUnknownAdditionalPropertiesDiscriminatedDerived.kind = kind; deserializedExtendsUnknownAdditionalPropertiesDiscriminatedDerived.age = age; deserializedExtendsUnknownAdditionalPropertiesDiscriminatedDerived .setAdditionalProperties(additionalProperties); diff --git a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminated.java b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminated.java index 8c4c968c3d..b3f15aeaa3 100644 --- a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminated.java +++ b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminated.java @@ -59,18 +59,6 @@ public String getKind() { return this.kind; } - /** - * Set the kind property: The discriminator. - * - * @param kind the kind value to set. - * @return the IsUnknownAdditionalPropertiesDiscriminated object itself. - */ - @Generated - protected IsUnknownAdditionalPropertiesDiscriminated setKind(String kind) { - this.kind = kind; - return this; - } - /** * Get the name property: The name property. * diff --git a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminatedDerived.java b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminatedDerived.java index bf2c34c365..2b8c64bb8b 100644 --- a/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminatedDerived.java +++ b/typespec-tests/src/main/java/com/type/property/additionalproperties/models/IsUnknownAdditionalPropertiesDiscriminatedDerived.java @@ -19,6 +19,12 @@ @Fluent public final class IsUnknownAdditionalPropertiesDiscriminatedDerived extends IsUnknownAdditionalPropertiesDiscriminated { + /* + * The discriminator + */ + @Generated + private String kind = "derived"; + /* * The index property */ @@ -40,10 +46,20 @@ public final class IsUnknownAdditionalPropertiesDiscriminatedDerived @Generated public IsUnknownAdditionalPropertiesDiscriminatedDerived(String name, int index) { super(name); - setKind("derived"); this.index = index; } + /** + * Get the kind property: The discriminator. + * + * @return the kind value. + */ + @Generated + @Override + public String getKind() { + return this.kind; + } + /** * Get the index property: The index property. * @@ -84,8 +100,8 @@ public IsUnknownAdditionalPropertiesDiscriminatedDerived setAge(Double age) { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", getName()); - jsonWriter.writeStringField("kind", getKind()); jsonWriter.writeIntField("index", this.index); + jsonWriter.writeStringField("kind", this.kind); jsonWriter.writeNumberField("age", this.age); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -107,8 +123,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { public static IsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { String name = null; - String kind = "derived"; int index = 0; + String kind = "derived"; Double age = null; Map additionalProperties = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -117,10 +133,10 @@ public static IsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(JsonRea if ("name".equals(fieldName)) { name = reader.getString(); - } else if ("kind".equals(fieldName)) { - kind = reader.getString(); } else if ("index".equals(fieldName)) { index = reader.getInt(); + } else if ("kind".equals(fieldName)) { + kind = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getDouble); } else { @@ -133,7 +149,7 @@ public static IsUnknownAdditionalPropertiesDiscriminatedDerived fromJson(JsonRea } IsUnknownAdditionalPropertiesDiscriminatedDerived deserializedIsUnknownAdditionalPropertiesDiscriminatedDerived = new IsUnknownAdditionalPropertiesDiscriminatedDerived(name, index); - deserializedIsUnknownAdditionalPropertiesDiscriminatedDerived.setKind(kind); + deserializedIsUnknownAdditionalPropertiesDiscriminatedDerived.kind = kind; deserializedIsUnknownAdditionalPropertiesDiscriminatedDerived.age = age; deserializedIsUnknownAdditionalPropertiesDiscriminatedDerived.setAdditionalProperties(additionalProperties); diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Cookiecuttershark.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Cookiecuttershark.java index d7e733abb8..d238d0e6e5 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Cookiecuttershark.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Cookiecuttershark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Cookiecuttershark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "cookiecuttershark"; + /** * Creates an instance of Cookiecuttershark class. * @@ -27,7 +32,16 @@ public final class Cookiecuttershark extends Shark { */ public Cookiecuttershark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("cookiecuttershark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -76,10 +90,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); return jsonWriter.writeEndObject(); } @@ -97,10 +111,10 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "cookiecuttershark"; String species = null; List siblings = null; Integer age = null; + String fishtype = "cookiecuttershark"; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -111,24 +125,24 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else { reader.skipChildren(); } } if (lengthFound && birthdayFound) { Cookiecuttershark deserializedCookiecuttershark = new Cookiecuttershark(length, birthday); - deserializedCookiecuttershark.setFishtype(fishtype); deserializedCookiecuttershark.setSpecies(species); deserializedCookiecuttershark.setSiblings(siblings); deserializedCookiecuttershark.setAge(age); + deserializedCookiecuttershark.fishtype = fishtype; return deserializedCookiecuttershark; } diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotFish.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotFish.java index 5a262fa305..723dd5e9cb 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotFish.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotFish.java @@ -42,17 +42,6 @@ public String getFishType() { return this.fishType; } - /** - * Set the fishType property: The fish.type property. - * - * @param fishType the fishType value to set. - * @return the DotFish object itself. - */ - protected DotFish setFishType(String fishType) { - this.fishType = fishType; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotSalmon.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotSalmon.java index e0d632057f..b893df9068 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/DotSalmon.java @@ -15,6 +15,11 @@ */ @Immutable public final class DotSalmon extends DotFish { + /* + * The fish.type property. + */ + private String fishType = "DotSalmon"; + /* * The location property. */ @@ -29,7 +34,16 @@ public final class DotSalmon extends DotFish { * Creates an instance of DotSalmon class. */ private DotSalmon() { - setFishType("DotSalmon"); + } + + /** + * Get the fishType property: The fish.type property. + * + * @return the fishType value. + */ + @Override + public String getFishType() { + return this.fishType; } /** @@ -66,8 +80,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("fish.type", getFishType()); jsonWriter.writeStringField("species", getSpecies()); + jsonWriter.writeStringField("fish.type", this.fishType); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -87,10 +101,10 @@ public static DotSalmon fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fish.type".equals(fieldName)) { - deserializedDotSalmon.setFishType(reader.getString()); - } else if ("species".equals(fieldName)) { + if ("species".equals(fieldName)) { deserializedDotSalmon.setSpecies(reader.getString()); + } else if ("fish.type".equals(fieldName)) { + deserializedDotSalmon.fishType = reader.getString(); } else if ("location".equals(fieldName)) { deserializedDotSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Fish.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Fish.java index ada268addf..eab366c06b 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Fish.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Fish.java @@ -56,17 +56,6 @@ public String getFishtype() { return this.fishtype; } - /** - * Set the fishtype property: The fishtype property. - * - * @param fishtype the fishtype value to set. - * @return the Fish object itself. - */ - protected Fish setFishtype(String fishtype) { - this.fishtype = fishtype; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Goblinshark.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Goblinshark.java index fe7e1078d9..1a39f72126 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Goblinshark.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Goblinshark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Goblinshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "goblin"; + /* * The jawsize property. */ @@ -37,7 +42,16 @@ public final class Goblinshark extends Shark { */ public Goblinshark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("goblin"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -126,10 +140,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("jawsize", this.jawsize); jsonWriter.writeStringField("color", this.color == null ? null : this.color.toString()); return jsonWriter.writeEndObject(); @@ -149,10 +163,10 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "goblin"; String species = null; List siblings = null; Integer age = null; + String fishtype = "goblin"; Integer jawsize = null; GoblinSharkColor color = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -165,14 +179,14 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("jawsize".equals(fieldName)) { jawsize = reader.getNullable(JsonReader::getInt); } else if ("color".equals(fieldName)) { @@ -183,10 +197,10 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound && birthdayFound) { Goblinshark deserializedGoblinshark = new Goblinshark(length, birthday); - deserializedGoblinshark.setFishtype(fishtype); deserializedGoblinshark.setSpecies(species); deserializedGoblinshark.setSiblings(siblings); deserializedGoblinshark.setAge(age); + deserializedGoblinshark.fishtype = fishtype; deserializedGoblinshark.jawsize = jawsize; deserializedGoblinshark.color = color; diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyBaseType.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyBaseType.java index a69f765f59..1c5ba341ac 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyBaseType.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyBaseType.java @@ -47,17 +47,6 @@ public MyKind getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the MyBaseType object itself. - */ - protected MyBaseType setKind(MyKind kind) { - this.kind = kind; - return this; - } - /** * Get the propB1 property: The propB1 property. * diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyDerivedType.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyDerivedType.java index 2319617c48..82914e38ca 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyDerivedType.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/MyDerivedType.java @@ -15,6 +15,11 @@ */ @Immutable public final class MyDerivedType extends MyBaseType { + /* + * The kind property. + */ + private MyKind kind = MyKind.KIND1; + /* * The propD1 property. */ @@ -24,7 +29,16 @@ public final class MyDerivedType extends MyBaseType { * Creates an instance of MyDerivedType class. */ private MyDerivedType() { - setKind(MyKind.KIND1); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Override + public MyKind getKind() { + return this.kind; } /** @@ -52,8 +66,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); jsonWriter.writeStringField("propB1", getPropB1()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); jsonWriter.writeStringField("propD1", this.propD1); if (getPropBH1() != null) { jsonWriter.writeStartObject("helper"); @@ -77,10 +91,10 @@ public static MyDerivedType fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { - deserializedMyDerivedType.setKind(MyKind.fromString(reader.getString())); - } else if ("propB1".equals(fieldName)) { + if ("propB1".equals(fieldName)) { deserializedMyDerivedType.setPropB1(reader.getString()); + } else if ("kind".equals(fieldName)) { + deserializedMyDerivedType.kind = MyKind.fromString(reader.getString()); } else if ("propD1".equals(fieldName)) { deserializedMyDerivedType.propD1 = reader.getString(); } else if ("helper".equals(fieldName) && reader.currentToken() == JsonToken.START_OBJECT) { diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Salmon.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Salmon.java index f25629bdd6..4c911c1d42 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Salmon.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Salmon.java @@ -16,6 +16,11 @@ */ @Fluent public class Salmon extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "salmon"; + /* * The location property. */ @@ -33,7 +38,16 @@ public class Salmon extends Fish { */ public Salmon(float length) { super(length); - setFishtype("salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -111,9 +125,9 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -156,9 +170,9 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "salmon"; String species = null; List siblings = null; + String fishtype = "salmon"; String location = null; Boolean iswild = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -168,12 +182,12 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("location".equals(fieldName)) { location = reader.getString(); } else if ("iswild".equals(fieldName)) { @@ -184,9 +198,9 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti } if (lengthFound) { Salmon deserializedSalmon = new Salmon(length); - deserializedSalmon.setFishtype(fishtype); deserializedSalmon.setSpecies(species); deserializedSalmon.setSiblings(siblings); + deserializedSalmon.fishtype = fishtype; deserializedSalmon.location = location; deserializedSalmon.iswild = iswild; diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Sawshark.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Sawshark.java index 2af1448318..39f0ce8e6e 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Sawshark.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Sawshark.java @@ -20,6 +20,11 @@ */ @Fluent public final class Sawshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "sawshark"; + /* * The picture property. */ @@ -33,7 +38,16 @@ public final class Sawshark extends Shark { */ public Sawshark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("sawshark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -102,10 +116,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeBinaryField("picture", this.picture); return jsonWriter.writeEndObject(); } @@ -124,10 +138,10 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "sawshark"; String species = null; List siblings = null; Integer age = null; + String fishtype = "sawshark"; byte[] picture = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -139,14 +153,14 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("picture".equals(fieldName)) { picture = reader.getBinary(); } else { @@ -155,10 +169,10 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound && birthdayFound) { Sawshark deserializedSawshark = new Sawshark(length, birthday); - deserializedSawshark.setFishtype(fishtype); deserializedSawshark.setSpecies(species); deserializedSawshark.setSiblings(siblings); deserializedSawshark.setAge(age); + deserializedSawshark.fishtype = fishtype; deserializedSawshark.picture = picture; return deserializedSawshark; diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Shark.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Shark.java index 8e5516624f..ba5dff8bf5 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Shark.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/Shark.java @@ -20,6 +20,11 @@ */ @Fluent public class Shark extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "shark"; + /* * The age property. */ @@ -38,10 +43,19 @@ public class Shark extends Fish { */ public Shark(float length, OffsetDateTime birthday) { super(length); - setFishtype("shark"); this.birthday = birthday; } + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; + } + /** * Get the age property: The age property. * @@ -112,11 +126,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("birthday", this.birthday == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.birthday)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("age", this.age); return jsonWriter.writeEndObject(); } @@ -162,11 +176,11 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "shark"; String species = null; List siblings = null; boolean birthdayFound = false; OffsetDateTime birthday = null; + String fishtype = "shark"; Integer age = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -175,8 +189,6 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { @@ -184,6 +196,8 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); } else { @@ -192,9 +206,9 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } if (lengthFound && birthdayFound) { Shark deserializedShark = new Shark(length, birthday); - deserializedShark.setFishtype(fishtype); deserializedShark.setSpecies(species); deserializedShark.setSiblings(siblings); + deserializedShark.fishtype = fishtype; deserializedShark.age = age; return deserializedShark; diff --git a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/SmartSalmon.java b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/SmartSalmon.java index 28ce6226e3..d508e0cc9e 100644 --- a/vanilla-tests/src/main/java/fixtures/bodycomplex/models/SmartSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/bodycomplex/models/SmartSalmon.java @@ -18,6 +18,11 @@ */ @Fluent public final class SmartSalmon extends Salmon { + /* + * The fishtype property. + */ + private String fishtype = "smart_salmon"; + /* * The college_degree property. */ @@ -35,7 +40,16 @@ public final class SmartSalmon extends Salmon { */ public SmartSalmon(float length) { super(length); - setFishtype("smart_salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -131,11 +145,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("location", getLocation()); jsonWriter.writeBooleanField("iswild", iswild()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("college_degree", this.collegeDegree); if (additionalProperties != null) { for (Map.Entry additionalProperty : additionalProperties.entrySet()) { @@ -157,11 +171,11 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "smart_salmon"; String species = null; List siblings = null; String location = null; Boolean iswild = null; + String fishtype = "smart_salmon"; String collegeDegree = null; Map additionalProperties = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -171,8 +185,6 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { @@ -181,6 +193,8 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { location = reader.getString(); } else if ("iswild".equals(fieldName)) { iswild = reader.getNullable(JsonReader::getBoolean); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("college_degree".equals(fieldName)) { collegeDegree = reader.getString(); } else { @@ -193,11 +207,11 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound) { SmartSalmon deserializedSmartSalmon = new SmartSalmon(length); - deserializedSmartSalmon.setFishtype(fishtype); deserializedSmartSalmon.setSpecies(species); deserializedSmartSalmon.setSiblings(siblings); deserializedSmartSalmon.setLocation(location); deserializedSmartSalmon.setIswild(iswild); + deserializedSmartSalmon.fishtype = fishtype; deserializedSmartSalmon.collegeDegree = collegeDegree; deserializedSmartSalmon.additionalProperties = additionalProperties; diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Dog.java b/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Dog.java index 654ab68921..705d6d0c5c 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Dog.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Dog.java @@ -42,17 +42,6 @@ public DogKind getKind() { return this.kind; } - /** - * Set the kind property: discriminator property. - * - * @param kind the kind value to set. - * @return the Dog object itself. - */ - protected Dog setKind(DogKind kind) { - this.kind = kind; - return this; - } - /** * Get the weight property: Weight of the dog. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Golden.java b/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Golden.java index a8f91ad88a..80b6278ff7 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Golden.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorenum/models/Golden.java @@ -15,11 +15,25 @@ */ @Fluent public final class Golden extends Dog { + /* + * discriminator property + */ + private DogKind kind = DogKind.GOLDEN; + /** * Creates an instance of Golden class. */ public Golden() { - setKind(DogKind.GOLDEN); + } + + /** + * Get the kind property: discriminator property. + * + * @return the kind value. + */ + @Override + public DogKind getKind() { + return this.kind; } /** @@ -48,7 +62,7 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("weight", getWeight()); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); return jsonWriter.writeEndObject(); } @@ -70,7 +84,7 @@ public static Golden fromJson(JsonReader jsonReader) throws IOException { if ("weight".equals(fieldName)) { deserializedGolden.setWeight(reader.getInt()); } else if ("kind".equals(fieldName)) { - deserializedGolden.setKind(DogKind.fromString(reader.getString())); + deserializedGolden.kind = DogKind.fromString(reader.getString()); } else { reader.skipChildren(); } diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertCriteria.java index 8c2cf40902..df58b4d406 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertCriteria.java @@ -44,17 +44,6 @@ public Odatatype getOdataType() { return this.odataType; } - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - protected MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java index 1cd3e54953..5c716fc985 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/clientflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -18,6 +18,11 @@ */ @Fluent public final class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { + /* + * specifies the type of the alert criteria. + */ + private Odatatype odataType = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; + /* * The list of metric criteria for this 'all of' operation. */ @@ -27,7 +32,16 @@ public final class MetricAlertSingleResourceMultipleMetricCriteria extends Metri * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); + } + + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + @Override + public Odatatype getOdataType() { + return this.odataType; } /** @@ -66,7 +80,7 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("odata.type", getOdataType() == null ? null : getOdataType().toString()); + jsonWriter.writeStringField("odata.type", this.odataType == null ? null : this.odataType.toString()); jsonWriter.writeArrayField("allOf", this.allOf, (writer, element) -> writer.writeString(element)); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -93,8 +107,8 @@ public static MetricAlertSingleResourceMultipleMetricCriteria fromJson(JsonReade reader.nextToken(); if ("odata.type".equals(fieldName)) { - deserializedMetricAlertSingleResourceMultipleMetricCriteria - .setOdataType(Odatatype.fromString(reader.getString())); + deserializedMetricAlertSingleResourceMultipleMetricCriteria.odataType + = Odatatype.fromString(reader.getString()); } else if ("allOf".equals(fieldName)) { List allOf = reader.readArray(reader1 -> reader1.getString()); deserializedMetricAlertSingleResourceMultipleMetricCriteria.allOf = allOf; diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertCriteria.java index 08a4eb3fc6..78041a223a 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertCriteria.java @@ -44,17 +44,6 @@ public Odatatype getOdataType() { return this.odataType; } - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - protected MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertSingleResourceMultipleMetricCriteria.java index 77f2a7bffe..bc0ac6d271 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -18,6 +18,11 @@ */ @Fluent public final class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { + /* + * specifies the type of the alert criteria. + */ + private Odatatype odataType = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; + /* * The list of metric criteria for this 'all of' operation. */ @@ -27,7 +32,16 @@ public final class MetricAlertSingleResourceMultipleMetricCriteria extends Metri * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); + } + + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + @Override + public Odatatype getOdataType() { + return this.odataType; } /** @@ -66,7 +80,7 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("odata.type", getOdataType() == null ? null : getOdataType().toString()); + jsonWriter.writeStringField("odata.type", this.odataType == null ? null : this.odataType.toString()); jsonWriter.writeArrayField("allOf", this.allOf, (writer, element) -> writer.writeString(element)); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -93,8 +107,8 @@ public static MetricAlertSingleResourceMultipleMetricCriteria fromJson(JsonReade reader.nextToken(); if ("odata.type".equals(fieldName)) { - deserializedMetricAlertSingleResourceMultipleMetricCriteria - .setOdataType(Odatatype.fromString(reader.getString())); + deserializedMetricAlertSingleResourceMultipleMetricCriteria.odataType + = Odatatype.fromString(reader.getString()); } else if ("allOf".equals(fieldName)) { List allOf = reader.readArray(reader1 -> reader1.getString()); deserializedMetricAlertSingleResourceMultipleMetricCriteria.allOf = allOf; diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertCriteria.java index 44dd8493ce..006890b2b9 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertCriteria.java @@ -44,17 +44,6 @@ public Odatatype getOdataType() { return this.odataType; } - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - protected MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java index d07012a9b8..b53c732e9d 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/noflatten/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -18,6 +18,11 @@ */ @Fluent public final class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { + /* + * specifies the type of the alert criteria. + */ + private Odatatype odataType = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; + /* * The list of metric criteria for this 'all of' operation. */ @@ -27,7 +32,16 @@ public final class MetricAlertSingleResourceMultipleMetricCriteria extends Metri * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); + } + + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + @Override + public Odatatype getOdataType() { + return this.odataType; } /** @@ -66,7 +80,7 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("odata.type", getOdataType() == null ? null : getOdataType().toString()); + jsonWriter.writeStringField("odata.type", this.odataType == null ? null : this.odataType.toString()); jsonWriter.writeArrayField("allOf", this.allOf, (writer, element) -> writer.writeString(element)); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -93,8 +107,8 @@ public static MetricAlertSingleResourceMultipleMetricCriteria fromJson(JsonReade reader.nextToken(); if ("odata.type".equals(fieldName)) { - deserializedMetricAlertSingleResourceMultipleMetricCriteria - .setOdataType(Odatatype.fromString(reader.getString())); + deserializedMetricAlertSingleResourceMultipleMetricCriteria.odataType + = Odatatype.fromString(reader.getString()); } else if ("allOf".equals(fieldName)) { List allOf = reader.readArray(reader1 -> reader1.getString()); deserializedMetricAlertSingleResourceMultipleMetricCriteria.allOf = allOf; diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertCriteria.java index 3931d507bb..8a442bf9c1 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertCriteria.java @@ -44,17 +44,6 @@ public Odatatype getOdataType() { return this.odataType; } - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - protected MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertSingleResourceMultipleMetricCriteria.java index a1f1a350a5..426fc29708 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorflattening/requirexmsflattened/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -18,6 +18,11 @@ */ @Fluent public final class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { + /* + * specifies the type of the alert criteria. + */ + private Odatatype odataType = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; + /* * The list of metric criteria for this 'all of' operation. */ @@ -27,7 +32,16 @@ public final class MetricAlertSingleResourceMultipleMetricCriteria extends Metri * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); + } + + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + @Override + public Odatatype getOdataType() { + return this.odataType; } /** @@ -66,7 +80,7 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("odata.type", getOdataType() == null ? null : getOdataType().toString()); + jsonWriter.writeStringField("odata.type", this.odataType == null ? null : this.odataType.toString()); jsonWriter.writeArrayField("allOf", this.allOf, (writer, element) -> writer.writeString(element)); if (getAdditionalProperties() != null) { for (Map.Entry additionalProperty : getAdditionalProperties().entrySet()) { @@ -93,8 +107,8 @@ public static MetricAlertSingleResourceMultipleMetricCriteria fromJson(JsonReade reader.nextToken(); if ("odata.type".equals(fieldName)) { - deserializedMetricAlertSingleResourceMultipleMetricCriteria - .setOdataType(Odatatype.fromString(reader.getString())); + deserializedMetricAlertSingleResourceMultipleMetricCriteria.odataType + = Odatatype.fromString(reader.getString()); } else if ("allOf".equals(fieldName)) { List allOf = reader.readArray(reader1 -> reader1.getString()); deserializedMetricAlertSingleResourceMultipleMetricCriteria.allOf = allOf; diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorsetter/implementation/models/Dog.java b/vanilla-tests/src/main/java/fixtures/discriminatorsetter/implementation/models/Dog.java index 394c0eaa58..b438bd17bf 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorsetter/implementation/models/Dog.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorsetter/implementation/models/Dog.java @@ -43,17 +43,6 @@ public DogKind getKind() { return this.kind; } - /** - * Set the kind property: discriminator property. - * - * @param kind the kind value to set. - * @return the Dog object itself. - */ - protected Dog setKind(DogKind kind) { - this.kind = kind; - return this; - } - /** * Get the weight property: Weight of the dog. * diff --git a/vanilla-tests/src/main/java/fixtures/discriminatorsetter/models/Golden.java b/vanilla-tests/src/main/java/fixtures/discriminatorsetter/models/Golden.java index e2baf0cc23..21faeff217 100644 --- a/vanilla-tests/src/main/java/fixtures/discriminatorsetter/models/Golden.java +++ b/vanilla-tests/src/main/java/fixtures/discriminatorsetter/models/Golden.java @@ -17,11 +17,25 @@ */ @Fluent public final class Golden extends Dog { + /* + * discriminator property + */ + private DogKind kind = DogKind.GOLDEN; + /** * Creates an instance of Golden class. */ public Golden() { - setKind(DogKind.GOLDEN); + } + + /** + * Get the kind property: discriminator property. + * + * @return the kind value. + */ + @Override + public DogKind getKind() { + return this.kind; } /** @@ -50,7 +64,7 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeIntField("weight", getWeight()); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); return jsonWriter.writeEndObject(); } @@ -72,7 +86,7 @@ public static Golden fromJson(JsonReader jsonReader) throws IOException { if ("weight".equals(fieldName)) { deserializedGolden.setWeight(reader.getInt()); } else if ("kind".equals(fieldName)) { - deserializedGolden.setKind(DogKind.fromString(reader.getString())); + deserializedGolden.kind = DogKind.fromString(reader.getString()); } else { reader.skipChildren(); } diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java index 4556b7463f..cd9d78c1ed 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertCriteria.java @@ -60,17 +60,6 @@ public Odatatype getOdataType() { return this.odataType; } - /** - * Set the odataType property: specifies the type of the alert criteria. - * - * @param odataType the odataType value to set. - * @return the MetricAlertCriteria object itself. - */ - protected MetricAlertCriteria setOdataType(Odatatype odataType) { - this.odataType = odataType; - return this; - } - /** * Get the additionalProperties property: The rule criteria that defines the conditions of the alert rule. * diff --git a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java index dca2ef0f79..8f16333972 100644 --- a/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java +++ b/vanilla-tests/src/main/java/fixtures/inheritance/passdiscriminator/models/MetricAlertSingleResourceMultipleMetricCriteria.java @@ -6,6 +6,7 @@ import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeId; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.List; @@ -21,6 +22,13 @@ @JsonTypeName("Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria") @Fluent public final class MetricAlertSingleResourceMultipleMetricCriteria extends MetricAlertCriteria { + /* + * specifies the type of the alert criteria. + */ + @JsonTypeId + @JsonProperty(value = "odata.type", required = true) + private Odatatype odataType = Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA; + /* * The list of metric criteria for this 'all of' operation. */ @@ -31,7 +39,16 @@ public final class MetricAlertSingleResourceMultipleMetricCriteria extends Metri * Creates an instance of MetricAlertSingleResourceMultipleMetricCriteria class. */ public MetricAlertSingleResourceMultipleMetricCriteria() { - setOdataType(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA); + } + + /** + * Get the odataType property: specifies the type of the alert criteria. + * + * @return the odataType value. + */ + @Override + public Odatatype getOdataType() { + return this.odataType; } /** diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Cookiecuttershark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Cookiecuttershark.java index 4456c79440..4d2ea39f33 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Cookiecuttershark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Cookiecuttershark.java @@ -18,11 +18,25 @@ */ @Fluent public final class Cookiecuttershark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "cookiecuttershark"; + /** * Creates an instance of Cookiecuttershark class. */ public Cookiecuttershark() { - setFishtype("cookiecuttershark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -89,10 +103,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); return jsonWriter.writeEndObject(); } @@ -116,8 +130,6 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti } else if ("birthday".equals(fieldName)) { deserializedCookiecuttershark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedCookiecuttershark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedCookiecuttershark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -125,6 +137,8 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti deserializedCookiecuttershark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedCookiecuttershark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedCookiecuttershark.fishtype = reader.getString(); } else { reader.skipChildren(); } diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotFish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotFish.java index 77a038724d..1837c0763a 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotFish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotFish.java @@ -42,17 +42,6 @@ public String getFishType() { return this.fishType; } - /** - * Set the fishType property: The fish.type property. - * - * @param fishType the fishType value to set. - * @return the DotFish object itself. - */ - protected DotFish setFishType(String fishType) { - this.fishType = fishType; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotSalmon.java index 46c1a33861..c9cf8fba4a 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/DotSalmon.java @@ -15,6 +15,11 @@ */ @Fluent public final class DotSalmon extends DotFish { + /* + * The fish.type property. + */ + private String fishType = "DotSalmon"; + /* * The location property. */ @@ -29,7 +34,16 @@ public final class DotSalmon extends DotFish { * Creates an instance of DotSalmon class. */ public DotSalmon() { - setFishType("DotSalmon"); + } + + /** + * Get the fishType property: The fish.type property. + * + * @return the fishType value. + */ + @Override + public String getFishType() { + return this.fishType; } /** @@ -97,8 +111,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("fish.type", getFishType()); jsonWriter.writeStringField("species", getSpecies()); + jsonWriter.writeStringField("fish.type", this.fishType); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -118,10 +132,10 @@ public static DotSalmon fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fish.type".equals(fieldName)) { - deserializedDotSalmon.setFishType(reader.getString()); - } else if ("species".equals(fieldName)) { + if ("species".equals(fieldName)) { deserializedDotSalmon.setSpecies(reader.getString()); + } else if ("fish.type".equals(fieldName)) { + deserializedDotSalmon.fishType = reader.getString(); } else if ("location".equals(fieldName)) { deserializedDotSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Fish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Fish.java index 3457d3f2b0..6e2cb4e4b8 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Fish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Fish.java @@ -53,17 +53,6 @@ public String getFishtype() { return this.fishtype; } - /** - * Set the fishtype property: The fishtype property. - * - * @param fishtype the fishtype value to set. - * @return the Fish object itself. - */ - protected Fish setFishtype(String fishtype) { - this.fishtype = fishtype; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Goblinshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Goblinshark.java index 6ee10ec694..bfc0c5b294 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Goblinshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Goblinshark.java @@ -18,6 +18,11 @@ */ @Fluent public final class Goblinshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "goblin"; + /* * The jawsize property. */ @@ -32,7 +37,16 @@ public final class Goblinshark extends Shark { * Creates an instance of Goblinshark class. */ public Goblinshark() { - setFishtype("goblin"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -139,10 +153,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("jawsize", this.jawsize); jsonWriter.writeStringField("color", this.color == null ? null : this.color.toString()); return jsonWriter.writeEndObject(); @@ -168,8 +182,6 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedGoblinshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedGoblinshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedGoblinshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -177,6 +189,8 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { deserializedGoblinshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedGoblinshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedGoblinshark.fishtype = reader.getString(); } else if ("jawsize".equals(fieldName)) { deserializedGoblinshark.jawsize = reader.getNullable(JsonReader::getInt); } else if ("color".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyBaseType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyBaseType.java index 8eab1a8d3c..fe90373b0a 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyBaseType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyBaseType.java @@ -47,17 +47,6 @@ public MyKind getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the MyBaseType object itself. - */ - protected MyBaseType setKind(MyKind kind) { - this.kind = kind; - return this; - } - /** * Get the propB1 property: The propB1 property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyDerivedType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyDerivedType.java index e053bca9e4..67484f1d8b 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyDerivedType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/MyDerivedType.java @@ -15,6 +15,11 @@ */ @Fluent public final class MyDerivedType extends MyBaseType { + /* + * The kind property. + */ + private MyKind kind = MyKind.KIND1; + /* * The propD1 property. */ @@ -24,7 +29,16 @@ public final class MyDerivedType extends MyBaseType { * Creates an instance of MyDerivedType class. */ public MyDerivedType() { - setKind(MyKind.KIND1); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Override + public MyKind getKind() { + return this.kind; } /** @@ -81,8 +95,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); jsonWriter.writeStringField("propB1", getPropB1()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); jsonWriter.writeStringField("propD1", this.propD1); if (getPropBH1() != null) { jsonWriter.writeStartObject("helper"); @@ -106,10 +120,10 @@ public static MyDerivedType fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { - deserializedMyDerivedType.setKind(MyKind.fromString(reader.getString())); - } else if ("propB1".equals(fieldName)) { + if ("propB1".equals(fieldName)) { deserializedMyDerivedType.setPropB1(reader.getString()); + } else if ("kind".equals(fieldName)) { + deserializedMyDerivedType.kind = MyKind.fromString(reader.getString()); } else if ("propD1".equals(fieldName)) { deserializedMyDerivedType.propD1 = reader.getString(); } else if ("helper".equals(fieldName) && reader.currentToken() == JsonToken.START_OBJECT) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Salmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Salmon.java index a5ae2ce9ab..ffd740e4c3 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Salmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Salmon.java @@ -16,6 +16,11 @@ */ @Fluent public class Salmon extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "salmon"; + /* * The location property. */ @@ -30,7 +35,16 @@ public class Salmon extends Fish { * Creates an instance of Salmon class. */ public Salmon() { - setFishtype("salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -117,9 +131,9 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -167,13 +181,13 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti if ("length".equals(fieldName)) { deserializedSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { List siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); deserializedSalmon.setSiblings(siblings); + } else if ("fishtype".equals(fieldName)) { + deserializedSalmon.fishtype = reader.getString(); } else if ("location".equals(fieldName)) { deserializedSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Sawshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Sawshark.java index 1dbe93ad17..e02400036c 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Sawshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Sawshark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Sawshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "sawshark"; + /* * The picture property. */ @@ -28,7 +33,16 @@ public final class Sawshark extends Shark { * Creates an instance of Sawshark class. */ public Sawshark() { - setFishtype("sawshark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -115,10 +129,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeBinaryField("picture", this.picture); return jsonWriter.writeEndObject(); } @@ -143,8 +157,6 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedSawshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedSawshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSawshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -152,6 +164,8 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { deserializedSawshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedSawshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedSawshark.fishtype = reader.getString(); } else if ("picture".equals(fieldName)) { deserializedSawshark.picture = reader.getBinary(); } else { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Shark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Shark.java index dd8fb8db1c..e0d7a9302a 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Shark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/Shark.java @@ -19,6 +19,11 @@ */ @Fluent public class Shark extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "shark"; + /* * The age property. */ @@ -33,7 +38,16 @@ public class Shark extends Fish { * Creates an instance of Shark class. */ public Shark() { - setFishtype("shark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -126,11 +140,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("birthday", this.birthday == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.birthday)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("age", this.age); return jsonWriter.writeEndObject(); } @@ -181,8 +195,6 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("length".equals(fieldName)) { deserializedShark.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedShark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedShark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -191,6 +203,8 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } else if ("birthday".equals(fieldName)) { deserializedShark.birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("fishtype".equals(fieldName)) { + deserializedShark.fishtype = reader.getString(); } else if ("age".equals(fieldName)) { deserializedShark.age = reader.getNullable(JsonReader::getInt); } else { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/SmartSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/SmartSalmon.java index c502cd0e3b..f32dd78440 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/SmartSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserialization/models/SmartSalmon.java @@ -18,6 +18,11 @@ */ @Fluent public final class SmartSalmon extends Salmon { + /* + * The fishtype property. + */ + private String fishtype = "smart_salmon"; + /* * The college_degree property. */ @@ -32,7 +37,16 @@ public final class SmartSalmon extends Salmon { * Creates an instance of SmartSalmon class. */ public SmartSalmon() { - setFishtype("smart_salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -137,11 +151,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("location", getLocation()); jsonWriter.writeBooleanField("iswild", iswild()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("college_degree", this.collegeDegree); if (additionalProperties != null) { for (Map.Entry additionalProperty : additionalProperties.entrySet()) { @@ -169,8 +183,6 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { if ("length".equals(fieldName)) { deserializedSmartSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSmartSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSmartSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -180,6 +192,8 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { deserializedSmartSalmon.setLocation(reader.getString()); } else if ("iswild".equals(fieldName)) { deserializedSmartSalmon.setIswild(reader.getNullable(JsonReader::getBoolean)); + } else if ("fishtype".equals(fieldName)) { + deserializedSmartSalmon.fishtype = reader.getString(); } else if ("college_degree".equals(fieldName)) { deserializedSmartSalmon.collegeDegree = reader.getString(); } else { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Cookiecuttershark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Cookiecuttershark.java index 7fa15e480c..a74607fab0 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Cookiecuttershark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Cookiecuttershark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Cookiecuttershark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "cookiecuttershark"; + /** * Creates an instance of Cookiecuttershark class. * @@ -27,7 +32,16 @@ public final class Cookiecuttershark extends Shark { */ public Cookiecuttershark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("cookiecuttershark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -76,10 +90,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); return jsonWriter.writeEndObject(); } @@ -97,10 +111,10 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "cookiecuttershark"; String species = null; List siblings = null; Integer age = null; + String fishtype = "cookiecuttershark"; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -111,24 +125,24 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else { reader.skipChildren(); } } if (lengthFound && birthdayFound) { Cookiecuttershark deserializedCookiecuttershark = new Cookiecuttershark(length, birthday); - deserializedCookiecuttershark.setFishtype(fishtype); deserializedCookiecuttershark.setSpecies(species); deserializedCookiecuttershark.setSiblings(siblings); deserializedCookiecuttershark.setAge(age); + deserializedCookiecuttershark.fishtype = fishtype; return deserializedCookiecuttershark; } diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotFish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotFish.java index 82a8845838..b94a14d12e 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotFish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotFish.java @@ -42,17 +42,6 @@ public String getFishType() { return this.fishType; } - /** - * Set the fishType property: The fish.type property. - * - * @param fishType the fishType value to set. - * @return the DotFish object itself. - */ - protected DotFish setFishType(String fishType) { - this.fishType = fishType; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotSalmon.java index 5c5cb705fa..e2c68cc9c8 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/DotSalmon.java @@ -15,6 +15,11 @@ */ @Fluent public final class DotSalmon extends DotFish { + /* + * The fish.type property. + */ + private String fishType = "DotSalmon"; + /* * The location property. */ @@ -29,7 +34,16 @@ public final class DotSalmon extends DotFish { * Creates an instance of DotSalmon class. */ public DotSalmon() { - setFishType("DotSalmon"); + } + + /** + * Get the fishType property: The fish.type property. + * + * @return the fishType value. + */ + @Override + public String getFishType() { + return this.fishType; } /** @@ -97,8 +111,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("fish.type", getFishType()); jsonWriter.writeStringField("species", getSpecies()); + jsonWriter.writeStringField("fish.type", this.fishType); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -118,10 +132,10 @@ public static DotSalmon fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fish.type".equals(fieldName)) { - deserializedDotSalmon.setFishType(reader.getString()); - } else if ("species".equals(fieldName)) { + if ("species".equals(fieldName)) { deserializedDotSalmon.setSpecies(reader.getString()); + } else if ("fish.type".equals(fieldName)) { + deserializedDotSalmon.fishType = reader.getString(); } else if ("location".equals(fieldName)) { deserializedDotSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Fish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Fish.java index db243dbe8f..71c5fc0ab5 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Fish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Fish.java @@ -56,17 +56,6 @@ public String getFishtype() { return this.fishtype; } - /** - * Set the fishtype property: The fishtype property. - * - * @param fishtype the fishtype value to set. - * @return the Fish object itself. - */ - protected Fish setFishtype(String fishtype) { - this.fishtype = fishtype; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Goblinshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Goblinshark.java index d4f1721487..3f2ff71bca 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Goblinshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Goblinshark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Goblinshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "goblin"; + /* * The jawsize property. */ @@ -37,7 +42,16 @@ public final class Goblinshark extends Shark { */ public Goblinshark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("goblin"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -126,10 +140,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("jawsize", this.jawsize); jsonWriter.writeStringField("color", this.color == null ? null : this.color.toString()); return jsonWriter.writeEndObject(); @@ -149,10 +163,10 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "goblin"; String species = null; List siblings = null; Integer age = null; + String fishtype = "goblin"; Integer jawsize = null; GoblinSharkColor color = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -165,14 +179,14 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("jawsize".equals(fieldName)) { jawsize = reader.getNullable(JsonReader::getInt); } else if ("color".equals(fieldName)) { @@ -183,10 +197,10 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound && birthdayFound) { Goblinshark deserializedGoblinshark = new Goblinshark(length, birthday); - deserializedGoblinshark.setFishtype(fishtype); deserializedGoblinshark.setSpecies(species); deserializedGoblinshark.setSiblings(siblings); deserializedGoblinshark.setAge(age); + deserializedGoblinshark.fishtype = fishtype; deserializedGoblinshark.jawsize = jawsize; deserializedGoblinshark.color = color; diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyBaseType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyBaseType.java index 13a2d8251a..4d6e716df4 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyBaseType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyBaseType.java @@ -47,17 +47,6 @@ public MyKind getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the MyBaseType object itself. - */ - protected MyBaseType setKind(MyKind kind) { - this.kind = kind; - return this; - } - /** * Get the propB1 property: The propB1 property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyDerivedType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyDerivedType.java index 27d70befa1..9546438090 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyDerivedType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/MyDerivedType.java @@ -15,6 +15,11 @@ */ @Fluent public final class MyDerivedType extends MyBaseType { + /* + * The kind property. + */ + private MyKind kind = MyKind.KIND1; + /* * The propD1 property. */ @@ -24,7 +29,16 @@ public final class MyDerivedType extends MyBaseType { * Creates an instance of MyDerivedType class. */ public MyDerivedType() { - setKind(MyKind.KIND1); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Override + public MyKind getKind() { + return this.kind; } /** @@ -81,8 +95,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); jsonWriter.writeStringField("propB1", getPropB1()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); jsonWriter.writeStringField("propD1", this.propD1); if (getPropBH1() != null) { jsonWriter.writeStartObject("helper"); @@ -106,10 +120,10 @@ public static MyDerivedType fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { - deserializedMyDerivedType.setKind(MyKind.fromString(reader.getString())); - } else if ("propB1".equals(fieldName)) { + if ("propB1".equals(fieldName)) { deserializedMyDerivedType.setPropB1(reader.getString()); + } else if ("kind".equals(fieldName)) { + deserializedMyDerivedType.kind = MyKind.fromString(reader.getString()); } else if ("propD1".equals(fieldName)) { deserializedMyDerivedType.propD1 = reader.getString(); } else if ("helper".equals(fieldName) && reader.currentToken() == JsonToken.START_OBJECT) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Salmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Salmon.java index 1b1e66041c..cd14a30aaf 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Salmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Salmon.java @@ -16,6 +16,11 @@ */ @Fluent public class Salmon extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "salmon"; + /* * The location property. */ @@ -33,7 +38,16 @@ public class Salmon extends Fish { */ public Salmon(float length) { super(length); - setFishtype("salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -111,9 +125,9 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -156,9 +170,9 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "salmon"; String species = null; List siblings = null; + String fishtype = "salmon"; String location = null; Boolean iswild = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -168,12 +182,12 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("location".equals(fieldName)) { location = reader.getString(); } else if ("iswild".equals(fieldName)) { @@ -184,9 +198,9 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti } if (lengthFound) { Salmon deserializedSalmon = new Salmon(length); - deserializedSalmon.setFishtype(fishtype); deserializedSalmon.setSpecies(species); deserializedSalmon.setSiblings(siblings); + deserializedSalmon.fishtype = fishtype; deserializedSalmon.location = location; deserializedSalmon.iswild = iswild; diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Sawshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Sawshark.java index a207c96a34..3526b5b9d4 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Sawshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Sawshark.java @@ -20,6 +20,11 @@ */ @Fluent public final class Sawshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "sawshark"; + /* * The picture property. */ @@ -33,7 +38,16 @@ public final class Sawshark extends Shark { */ public Sawshark(float length, OffsetDateTime birthday) { super(length, birthday); - setFishtype("sawshark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -102,10 +116,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeBinaryField("picture", this.picture); return jsonWriter.writeEndObject(); } @@ -124,10 +138,10 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { float length = 0.0f; boolean birthdayFound = false; OffsetDateTime birthday = null; - String fishtype = "sawshark"; String species = null; List siblings = null; Integer age = null; + String fishtype = "sawshark"; byte[] picture = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -139,14 +153,14 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("picture".equals(fieldName)) { picture = reader.getBinary(); } else { @@ -155,10 +169,10 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound && birthdayFound) { Sawshark deserializedSawshark = new Sawshark(length, birthday); - deserializedSawshark.setFishtype(fishtype); deserializedSawshark.setSpecies(species); deserializedSawshark.setSiblings(siblings); deserializedSawshark.setAge(age); + deserializedSawshark.fishtype = fishtype; deserializedSawshark.picture = picture; return deserializedSawshark; diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Shark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Shark.java index 08657a924f..1fb3f9d75d 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Shark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/Shark.java @@ -20,6 +20,11 @@ */ @Fluent public class Shark extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "shark"; + /* * The age property. */ @@ -38,10 +43,19 @@ public class Shark extends Fish { */ public Shark(float length, OffsetDateTime birthday) { super(length); - setFishtype("shark"); this.birthday = birthday; } + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; + } + /** * Get the age property: The age property. * @@ -112,11 +126,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("birthday", this.birthday == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.birthday)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("age", this.age); return jsonWriter.writeEndObject(); } @@ -162,11 +176,11 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "shark"; String species = null; List siblings = null; boolean birthdayFound = false; OffsetDateTime birthday = null; + String fishtype = "shark"; Integer age = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -175,8 +189,6 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { @@ -184,6 +196,8 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } else if ("birthday".equals(fieldName)) { birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); birthdayFound = true; + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("age".equals(fieldName)) { age = reader.getNullable(JsonReader::getInt); } else { @@ -192,9 +206,9 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } if (lengthFound && birthdayFound) { Shark deserializedShark = new Shark(length, birthday); - deserializedShark.setFishtype(fishtype); deserializedShark.setSpecies(species); deserializedShark.setSiblings(siblings); + deserializedShark.fishtype = fishtype; deserializedShark.age = age; return deserializedShark; diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/SmartSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/SmartSalmon.java index cbfdfdfd8d..ff3d72a595 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/SmartSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationctorargs/models/SmartSalmon.java @@ -18,6 +18,11 @@ */ @Fluent public final class SmartSalmon extends Salmon { + /* + * The fishtype property. + */ + private String fishtype = "smart_salmon"; + /* * The college_degree property. */ @@ -35,7 +40,16 @@ public final class SmartSalmon extends Salmon { */ public SmartSalmon(float length) { super(length); - setFishtype("smart_salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -131,11 +145,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("location", getLocation()); jsonWriter.writeBooleanField("iswild", iswild()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("college_degree", this.collegeDegree); if (additionalProperties != null) { for (Map.Entry additionalProperty : additionalProperties.entrySet()) { @@ -157,11 +171,11 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { boolean lengthFound = false; float length = 0.0f; - String fishtype = "smart_salmon"; String species = null; List siblings = null; String location = null; Boolean iswild = null; + String fishtype = "smart_salmon"; String collegeDegree = null; Map additionalProperties = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -171,8 +185,6 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { if ("length".equals(fieldName)) { length = reader.getFloat(); lengthFound = true; - } else if ("fishtype".equals(fieldName)) { - fishtype = reader.getString(); } else if ("species".equals(fieldName)) { species = reader.getString(); } else if ("siblings".equals(fieldName)) { @@ -181,6 +193,8 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { location = reader.getString(); } else if ("iswild".equals(fieldName)) { iswild = reader.getNullable(JsonReader::getBoolean); + } else if ("fishtype".equals(fieldName)) { + fishtype = reader.getString(); } else if ("college_degree".equals(fieldName)) { collegeDegree = reader.getString(); } else { @@ -193,11 +207,11 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { } if (lengthFound) { SmartSalmon deserializedSmartSalmon = new SmartSalmon(length); - deserializedSmartSalmon.setFishtype(fishtype); deserializedSmartSalmon.setSpecies(species); deserializedSmartSalmon.setSiblings(siblings); deserializedSmartSalmon.setLocation(location); deserializedSmartSalmon.setIswild(iswild); + deserializedSmartSalmon.fishtype = fishtype; deserializedSmartSalmon.collegeDegree = collegeDegree; deserializedSmartSalmon.additionalProperties = additionalProperties; diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Cookiecuttershark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Cookiecuttershark.java index e40072c845..029d41e7b9 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Cookiecuttershark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Cookiecuttershark.java @@ -18,11 +18,25 @@ */ @Fluent public final class Cookiecuttershark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "cookiecuttershark"; + /** * Creates an instance of Cookiecuttershark class. */ public Cookiecuttershark() { - setFishtype("cookiecuttershark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -89,10 +103,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); return jsonWriter.writeEndObject(); } @@ -116,8 +130,6 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti } else if ("birthday".equals(fieldName)) { deserializedCookiecuttershark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedCookiecuttershark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedCookiecuttershark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -125,6 +137,8 @@ public static Cookiecuttershark fromJson(JsonReader jsonReader) throws IOExcepti deserializedCookiecuttershark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedCookiecuttershark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedCookiecuttershark.fishtype = reader.getString(); } else { reader.skipChildren(); } diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotFish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotFish.java index e04554c25f..eaa1cdcebe 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotFish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotFish.java @@ -42,17 +42,6 @@ public String getFishType() { return this.fishType; } - /** - * Set the fishType property: The fish.type property. - * - * @param fishType the fishType value to set. - * @return the DotFish object itself. - */ - protected DotFish setFishType(String fishType) { - this.fishType = fishType; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotSalmon.java index 4d2cf317d9..2a440108c5 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/DotSalmon.java @@ -15,6 +15,11 @@ */ @Immutable public final class DotSalmon extends DotFish { + /* + * The fish.type property. + */ + private String fishType = "DotSalmon"; + /* * The location property. */ @@ -29,7 +34,16 @@ public final class DotSalmon extends DotFish { * Creates an instance of DotSalmon class. */ private DotSalmon() { - setFishType("DotSalmon"); + } + + /** + * Get the fishType property: The fish.type property. + * + * @return the fishType value. + */ + @Override + public String getFishType() { + return this.fishType; } /** @@ -66,8 +80,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("fish.type", getFishType()); jsonWriter.writeStringField("species", getSpecies()); + jsonWriter.writeStringField("fish.type", this.fishType); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -87,10 +101,10 @@ public static DotSalmon fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fish.type".equals(fieldName)) { - deserializedDotSalmon.setFishType(reader.getString()); - } else if ("species".equals(fieldName)) { + if ("species".equals(fieldName)) { deserializedDotSalmon.setSpecies(reader.getString()); + } else if ("fish.type".equals(fieldName)) { + deserializedDotSalmon.fishType = reader.getString(); } else if ("location".equals(fieldName)) { deserializedDotSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Fish.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Fish.java index f7f95b0960..4d993d1bf9 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Fish.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Fish.java @@ -53,17 +53,6 @@ public String getFishtype() { return this.fishtype; } - /** - * Set the fishtype property: The fishtype property. - * - * @param fishtype the fishtype value to set. - * @return the Fish object itself. - */ - protected Fish setFishtype(String fishtype) { - this.fishtype = fishtype; - return this; - } - /** * Get the species property: The species property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Goblinshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Goblinshark.java index c8fee027d9..92cfb1c95c 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Goblinshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Goblinshark.java @@ -18,6 +18,11 @@ */ @Fluent public final class Goblinshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "goblin"; + /* * The jawsize property. */ @@ -32,7 +37,16 @@ public final class Goblinshark extends Shark { * Creates an instance of Goblinshark class. */ public Goblinshark() { - setFishtype("goblin"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -139,10 +153,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("jawsize", this.jawsize); jsonWriter.writeStringField("color", this.color == null ? null : this.color.toString()); return jsonWriter.writeEndObject(); @@ -168,8 +182,6 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedGoblinshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedGoblinshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedGoblinshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -177,6 +189,8 @@ public static Goblinshark fromJson(JsonReader jsonReader) throws IOException { deserializedGoblinshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedGoblinshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedGoblinshark.fishtype = reader.getString(); } else if ("jawsize".equals(fieldName)) { deserializedGoblinshark.jawsize = reader.getNullable(JsonReader::getInt); } else if ("color".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyBaseType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyBaseType.java index 54073f3cbe..7d77e265c2 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyBaseType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyBaseType.java @@ -47,17 +47,6 @@ public MyKind getKind() { return this.kind; } - /** - * Set the kind property: The kind property. - * - * @param kind the kind value to set. - * @return the MyBaseType object itself. - */ - protected MyBaseType setKind(MyKind kind) { - this.kind = kind; - return this; - } - /** * Get the propB1 property: The propB1 property. * diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyDerivedType.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyDerivedType.java index fa85b8fc7c..ace215b6a3 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyDerivedType.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/MyDerivedType.java @@ -15,6 +15,11 @@ */ @Immutable public final class MyDerivedType extends MyBaseType { + /* + * The kind property. + */ + private MyKind kind = MyKind.KIND1; + /* * The propD1 property. */ @@ -24,7 +29,16 @@ public final class MyDerivedType extends MyBaseType { * Creates an instance of MyDerivedType class. */ private MyDerivedType() { - setKind(MyKind.KIND1); + } + + /** + * Get the kind property: The kind property. + * + * @return the kind value. + */ + @Override + public MyKind getKind() { + return this.kind; } /** @@ -52,8 +66,8 @@ public void validate() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("kind", getKind() == null ? null : getKind().toString()); jsonWriter.writeStringField("propB1", getPropB1()); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); jsonWriter.writeStringField("propD1", this.propD1); if (getPropBH1() != null) { jsonWriter.writeStartObject("helper"); @@ -77,10 +91,10 @@ public static MyDerivedType fromJson(JsonReader jsonReader) throws IOException { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { - deserializedMyDerivedType.setKind(MyKind.fromString(reader.getString())); - } else if ("propB1".equals(fieldName)) { + if ("propB1".equals(fieldName)) { deserializedMyDerivedType.setPropB1(reader.getString()); + } else if ("kind".equals(fieldName)) { + deserializedMyDerivedType.kind = MyKind.fromString(reader.getString()); } else if ("propD1".equals(fieldName)) { deserializedMyDerivedType.propD1 = reader.getString(); } else if ("helper".equals(fieldName) && reader.currentToken() == JsonToken.START_OBJECT) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Salmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Salmon.java index f0cec1b89f..2b2058904b 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Salmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Salmon.java @@ -16,6 +16,11 @@ */ @Fluent public class Salmon extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "salmon"; + /* * The location property. */ @@ -30,7 +35,16 @@ public class Salmon extends Fish { * Creates an instance of Salmon class. */ public Salmon() { - setFishtype("salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -117,9 +131,9 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("location", this.location); jsonWriter.writeBooleanField("iswild", this.iswild); return jsonWriter.writeEndObject(); @@ -167,13 +181,13 @@ static Salmon fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExcepti if ("length".equals(fieldName)) { deserializedSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { List siblings = reader.readArray(reader1 -> Fish.fromJson(reader1)); deserializedSalmon.setSiblings(siblings); + } else if ("fishtype".equals(fieldName)) { + deserializedSalmon.fishtype = reader.getString(); } else if ("location".equals(fieldName)) { deserializedSalmon.location = reader.getString(); } else if ("iswild".equals(fieldName)) { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Sawshark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Sawshark.java index d9d3492190..795cc925a2 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Sawshark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Sawshark.java @@ -19,6 +19,11 @@ */ @Fluent public final class Sawshark extends Shark { + /* + * The fishtype property. + */ + private String fishtype = "sawshark"; + /* * The picture property. */ @@ -28,7 +33,16 @@ public final class Sawshark extends Shark { * Creates an instance of Sawshark class. */ public Sawshark() { - setFishtype("sawshark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -115,10 +129,10 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeFloatField("length", getLength()); jsonWriter.writeStringField("birthday", getBirthday() == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(getBirthday())); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeNumberField("age", getAge()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeBinaryField("picture", this.picture); return jsonWriter.writeEndObject(); } @@ -143,8 +157,6 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { } else if ("birthday".equals(fieldName)) { deserializedSawshark.setBirthday( reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()))); - } else if ("fishtype".equals(fieldName)) { - deserializedSawshark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSawshark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -152,6 +164,8 @@ public static Sawshark fromJson(JsonReader jsonReader) throws IOException { deserializedSawshark.setSiblings(siblings); } else if ("age".equals(fieldName)) { deserializedSawshark.setAge(reader.getNullable(JsonReader::getInt)); + } else if ("fishtype".equals(fieldName)) { + deserializedSawshark.fishtype = reader.getString(); } else if ("picture".equals(fieldName)) { deserializedSawshark.picture = reader.getBinary(); } else { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Shark.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Shark.java index 5a2abba9ef..31f3c4dceb 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Shark.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/Shark.java @@ -19,6 +19,11 @@ */ @Fluent public class Shark extends Fish { + /* + * The fishtype property. + */ + private String fishtype = "shark"; + /* * The age property. */ @@ -33,7 +38,16 @@ public class Shark extends Fish { * Creates an instance of Shark class. */ public Shark() { - setFishtype("shark"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -126,11 +140,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("birthday", this.birthday == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.birthday)); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeNumberField("age", this.age); return jsonWriter.writeEndObject(); } @@ -181,8 +195,6 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio if ("length".equals(fieldName)) { deserializedShark.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedShark.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedShark.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -191,6 +203,8 @@ static Shark fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOExceptio } else if ("birthday".equals(fieldName)) { deserializedShark.birthday = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("fishtype".equals(fieldName)) { + deserializedShark.fishtype = reader.getString(); } else if ("age".equals(fieldName)) { deserializedShark.age = reader.getNullable(JsonReader::getInt); } else { diff --git a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/SmartSalmon.java b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/SmartSalmon.java index ee23dbafd1..53fd0a1b78 100644 --- a/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/SmartSalmon.java +++ b/vanilla-tests/src/main/java/fixtures/streamstyleserializationimmutableoutput/models/SmartSalmon.java @@ -18,6 +18,11 @@ */ @Fluent public final class SmartSalmon extends Salmon { + /* + * The fishtype property. + */ + private String fishtype = "smart_salmon"; + /* * The college_degree property. */ @@ -32,7 +37,16 @@ public final class SmartSalmon extends Salmon { * Creates an instance of SmartSalmon class. */ public SmartSalmon() { - setFishtype("smart_salmon"); + } + + /** + * Get the fishtype property: The fishtype property. + * + * @return the fishtype value. + */ + @Override + public String getFishtype() { + return this.fishtype; } /** @@ -137,11 +151,11 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeFloatField("length", getLength()); - jsonWriter.writeStringField("fishtype", getFishtype()); jsonWriter.writeStringField("species", getSpecies()); jsonWriter.writeArrayField("siblings", getSiblings(), (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("location", getLocation()); jsonWriter.writeBooleanField("iswild", iswild()); + jsonWriter.writeStringField("fishtype", this.fishtype); jsonWriter.writeStringField("college_degree", this.collegeDegree); if (additionalProperties != null) { for (Map.Entry additionalProperty : additionalProperties.entrySet()) { @@ -169,8 +183,6 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { if ("length".equals(fieldName)) { deserializedSmartSalmon.setLength(reader.getFloat()); - } else if ("fishtype".equals(fieldName)) { - deserializedSmartSalmon.setFishtype(reader.getString()); } else if ("species".equals(fieldName)) { deserializedSmartSalmon.setSpecies(reader.getString()); } else if ("siblings".equals(fieldName)) { @@ -180,6 +192,8 @@ public static SmartSalmon fromJson(JsonReader jsonReader) throws IOException { deserializedSmartSalmon.setLocation(reader.getString()); } else if ("iswild".equals(fieldName)) { deserializedSmartSalmon.setIswild(reader.getNullable(JsonReader::getBoolean)); + } else if ("fishtype".equals(fieldName)) { + deserializedSmartSalmon.fishtype = reader.getString(); } else if ("college_degree".equals(fieldName)) { deserializedSmartSalmon.collegeDegree = reader.getString(); } else { diff --git a/vanilla-tests/src/test/java/fixtures/inheritance/passdiscriminator/ValidateDiscriminatorIsPassedTests.java b/vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorIsPassedTests.java similarity index 84% rename from vanilla-tests/src/test/java/fixtures/inheritance/passdiscriminator/ValidateDiscriminatorIsPassedTests.java rename to vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorIsPassedTests.java index 2d498096e5..d3ba78c1d5 100644 --- a/vanilla-tests/src/test/java/fixtures/inheritance/passdiscriminator/ValidateDiscriminatorIsPassedTests.java +++ b/vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorIsPassedTests.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package fixtures.inheritance.passdiscriminator; +package fixtures.inheritance; import com.azure.core.util.BinaryData; import com.fasterxml.jackson.annotation.JsonProperty; @@ -34,12 +34,12 @@ public void superClassPassesDiscriminator() { } @Test - public void subClassAcceptsDiscriminator() throws IllegalAccessException { + public void subClassAcceptsDiscriminator() { JsonTypeInfo jsonTypeInfo = MetricAlertSingleResourceMultipleMetricCriteria.class .getAnnotation(JsonTypeInfo.class); assertNotNull(jsonTypeInfo); assertTrue(jsonTypeInfo.visible()); - assertEquals(JsonTypeInfo.As.EXISTING_PROPERTY, jsonTypeInfo.include()); + assertEquals(JsonTypeInfo.As.PROPERTY, jsonTypeInfo.include()); String discriminatorValue = MetricAlertSingleResourceMultipleMetricCriteria.class .getAnnotation(JsonTypeName.class) @@ -83,8 +83,13 @@ public void testJacksonSerialization() throws IOException { // de-serialization of unknown type String unknownJson = "{\"odata.type\": \"invalid\"}"; - MetricAlertCriteria criteria = BinaryData.fromString(unknownJson).toObject(MetricAlertCriteria.class); - assertEquals("invalid", criteria.getOdataType().toString()); - assertEquals(MetricAlertCriteria.class, criteria.getClass()); + MetricAlertCriteria unknown = BinaryData.fromString(unknownJson).toObject(MetricAlertCriteria.class); + assertEquals("invalid", unknown.getOdataType().toString()); + assertEquals(MetricAlertCriteria.class, unknown.getClass()); + // serialization keeps the unknown type + unknownJson = BinaryData.fromObject(unknown).toString(); + jsonNode = OBJECT_MAPPER.readTree(unknownJson); + assertEquals(1, jsonNode.size()); + assertEquals("invalid", jsonNode.get("odata.type").asText()); } } diff --git a/vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorTests.java b/vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorTests.java new file mode 100644 index 0000000000..5327bf0ce1 --- /dev/null +++ b/vanilla-tests/src/test/java/fixtures/inheritance/ValidateDiscriminatorTests.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package fixtures.inheritance; + +import com.azure.core.util.BinaryData; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import fixtures.discriminatorflattening.models.MetricAlertCriteria; +import fixtures.discriminatorflattening.models.MetricAlertSingleResourceMultipleMetricCriteria; +import fixtures.discriminatorflattening.models.Odatatype; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class ValidateDiscriminatorTests { + + private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @Test + public void testAzureJsonSerialization() throws IOException { + MetricAlertCriteria superclass = new MetricAlertCriteria(); + String superclassJson = BinaryData.fromObject(superclass).toString(); + JsonNode jsonNode = OBJECT_MAPPER.readTree(superclassJson); + assertEquals(1, jsonNode.size()); + assertEquals("MetricAlertCriteria", jsonNode.get("odata.type").asText()); + + MetricAlertCriteria subclass = new MetricAlertSingleResourceMultipleMetricCriteria(); + String subclassJson = BinaryData.fromObject(subclass).toString(); + jsonNode = OBJECT_MAPPER.readTree(subclassJson); + assertEquals(1, jsonNode.size()); + assertEquals(Odatatype.MICROSOFT_AZURE_MONITOR_SINGLE_RESOURCE_MULTIPLE_METRIC_CRITERIA.toString(), jsonNode.get("odata.type").asText()); + + // de-serialization of unknown type + String unknownJson = "{\"odata.type\": \"invalid\"}"; + MetricAlertCriteria unknown = BinaryData.fromString(unknownJson).toObject(MetricAlertCriteria.class); + assertEquals("invalid", unknown.getOdataType().toString()); + assertEquals(MetricAlertCriteria.class, unknown.getClass()); + // serialization keeps the unknown type + unknownJson = BinaryData.fromObject(unknown).toString(); + jsonNode = OBJECT_MAPPER.readTree(unknownJson); + assertEquals(1, jsonNode.size()); + assertEquals("invalid", jsonNode.get("odata.type").asText()); + } +}