From a8c098402cd39609e1117c3c38679a84478f98ee Mon Sep 17 00:00:00 2001 From: Rico Yao Date: Tue, 11 Jun 2019 13:55:57 -0700 Subject: [PATCH] Builder property variables should not have @SerializedName annotation I initially added this annotation thinking that it'd be nice to give developers the option to deserialize directly to a `Builder`. However, this isn't a good pattern since it would bypass the custom TypeAdapterFactory that each model provides. --- Examples/Java/Sources/Board.java | 20 +++--- Examples/Java/Sources/Everything.java | 72 +++++++++---------- Examples/Java/Sources/Image.java | 6 +- Examples/Java/Sources/Model.java | 2 +- Examples/Java/Sources/Pin.java | 34 ++++----- Examples/Java/Sources/User.java | 20 +++--- .../Java/Sources/VariableSubtitution.java | 8 +-- Sources/Core/JavaModelRenderer.swift | 2 +- 8 files changed, 82 insertions(+), 82 deletions(-) diff --git a/Examples/Java/Sources/Board.java b/Examples/Java/Sources/Board.java index f5164352..59c31ec2 100644 --- a/Examples/Java/Sources/Board.java +++ b/Examples/Java/Sources/Board.java @@ -213,16 +213,16 @@ public boolean getUrlIsSet() { public static class Builder { - @SerializedName("id") private @Nullable String uid; - @SerializedName("contributors") private @Nullable Set contributors; - @SerializedName("counts") private @Nullable Map counts; - @SerializedName("created_at") private @Nullable Date createdAt; - @SerializedName("creator") private @Nullable Map creator; - @SerializedName("creator_url") private @Nullable String creatorURL; - @SerializedName("description") private @Nullable String description; - @SerializedName("image") private @NonNull Image image; - @SerializedName("name") private @Nullable String name; - @SerializedName("url") private @Nullable String url; + private @Nullable String uid; + private @Nullable Set contributors; + private @Nullable Map counts; + private @Nullable Date createdAt; + private @Nullable Map creator; + private @Nullable String creatorURL; + private @Nullable String description; + private @NonNull Image image; + private @Nullable String name; + private @Nullable String url; private boolean[] _bits = new boolean[10]; diff --git a/Examples/Java/Sources/Everything.java b/Examples/Java/Sources/Everything.java index 921ab51f..dd1092b6 100644 --- a/Examples/Java/Sources/Everything.java +++ b/Examples/Java/Sources/Everything.java @@ -696,42 +696,42 @@ public boolean getUriPropIsSet() { public static class Builder { - @SerializedName("array_prop") private @Nullable List arrayProp; - @SerializedName("boolean_prop") private @Nullable Boolean booleanProp; - @SerializedName("char_enum") private @Nullable EverythingCharEnum charEnum; - @SerializedName("date_prop") private @Nullable Date dateProp; - @SerializedName("int_enum") private @Nullable EverythingIntEnum intEnum; - @SerializedName("int_prop") private @Nullable Integer intProp; - @SerializedName("list_polymorphic_values") private @Nullable List listPolymorphicValues; - @SerializedName("list_with_list_and_other_model_values") private @Nullable List> listWithListAndOtherModelValues; - @SerializedName("list_with_map_and_other_model_values") private @Nullable List> listWithMapAndOtherModelValues; - @SerializedName("list_with_object_values") private @Nullable List listWithObjectValues; - @SerializedName("list_with_other_model_values") private @Nullable List listWithOtherModelValues; - @SerializedName("list_with_primitive_values") private @Nullable List listWithPrimitiveValues; - @SerializedName("map_polymorphic_values") private @Nullable Map mapPolymorphicValues; - @SerializedName("map_prop") private @Nullable Map mapProp; - @SerializedName("map_with_list_and_other_model_values") private @Nullable Map> mapWithListAndOtherModelValues; - @SerializedName("map_with_map_and_other_model_values") private @Nullable Map> mapWithMapAndOtherModelValues; - @SerializedName("map_with_object_values") private @Nullable Map mapWithObjectValues; - @SerializedName("map_with_other_model_values") private @Nullable Map mapWithOtherModelValues; - @SerializedName("map_with_primitive_values") private @Nullable Map mapWithPrimitiveValues; - @SerializedName("nsinteger_enum") private @Nullable EverythingNsintegerEnum nsintegerEnum; - @SerializedName("nsuinteger_enum") private @Nullable EverythingNsuintegerEnum nsuintegerEnum; - @SerializedName("number_prop") private @Nullable Double numberProp; - @SerializedName("other_model_prop") private @Nullable User otherModelProp; - @SerializedName("polymorphic_prop") private @Nullable EverythingPolymorphicProp polymorphicProp; - @SerializedName("set_prop") private @Nullable Set setProp; - @SerializedName("set_prop_with_other_model_values") private @Nullable Set setPropWithOtherModelValues; - @SerializedName("set_prop_with_primitive_values") private @Nullable Set setPropWithPrimitiveValues; - @SerializedName("set_prop_with_values") private @Nullable Set setPropWithValues; - @SerializedName("short_enum") private @Nullable EverythingShortEnum shortEnum; - @SerializedName("string_enum") private @Nullable EverythingStringEnum stringEnum; - @SerializedName("string_prop") private @Nullable String stringProp; - @SerializedName("type") private @Nullable String type; - @SerializedName("unsigned_char_enum") private @Nullable EverythingUnsignedCharEnum unsignedCharEnum; - @SerializedName("unsigned_int_enum") private @Nullable EverythingUnsignedIntEnum unsignedIntEnum; - @SerializedName("unsigned_short_enum") private @Nullable EverythingUnsignedShortEnum unsignedShortEnum; - @SerializedName("uri_prop") private @Nullable String uriProp; + private @Nullable List arrayProp; + private @Nullable Boolean booleanProp; + private @Nullable EverythingCharEnum charEnum; + private @Nullable Date dateProp; + private @Nullable EverythingIntEnum intEnum; + private @Nullable Integer intProp; + private @Nullable List listPolymorphicValues; + private @Nullable List> listWithListAndOtherModelValues; + private @Nullable List> listWithMapAndOtherModelValues; + private @Nullable List listWithObjectValues; + private @Nullable List listWithOtherModelValues; + private @Nullable List listWithPrimitiveValues; + private @Nullable Map mapPolymorphicValues; + private @Nullable Map mapProp; + private @Nullable Map> mapWithListAndOtherModelValues; + private @Nullable Map> mapWithMapAndOtherModelValues; + private @Nullable Map mapWithObjectValues; + private @Nullable Map mapWithOtherModelValues; + private @Nullable Map mapWithPrimitiveValues; + private @Nullable EverythingNsintegerEnum nsintegerEnum; + private @Nullable EverythingNsuintegerEnum nsuintegerEnum; + private @Nullable Double numberProp; + private @Nullable User otherModelProp; + private @Nullable EverythingPolymorphicProp polymorphicProp; + private @Nullable Set setProp; + private @Nullable Set setPropWithOtherModelValues; + private @Nullable Set setPropWithPrimitiveValues; + private @Nullable Set setPropWithValues; + private @Nullable EverythingShortEnum shortEnum; + private @Nullable EverythingStringEnum stringEnum; + private @Nullable String stringProp; + private @Nullable String type; + private @Nullable EverythingUnsignedCharEnum unsignedCharEnum; + private @Nullable EverythingUnsignedIntEnum unsignedIntEnum; + private @Nullable EverythingUnsignedShortEnum unsignedShortEnum; + private @Nullable String uriProp; private boolean[] _bits = new boolean[36]; diff --git a/Examples/Java/Sources/Image.java b/Examples/Java/Sources/Image.java index 4c4cbfd5..f53723af 100644 --- a/Examples/Java/Sources/Image.java +++ b/Examples/Java/Sources/Image.java @@ -115,9 +115,9 @@ public boolean getWidthIsSet() { public static class Builder { - @SerializedName("height") private @Nullable Integer height; - @SerializedName("url") private @Nullable String url; - @SerializedName("width") private @Nullable Integer width; + private @Nullable Integer height; + private @Nullable String url; + private @Nullable Integer width; private boolean[] _bits = new boolean[3]; diff --git a/Examples/Java/Sources/Model.java b/Examples/Java/Sources/Model.java index 722a4294..0178dfde 100644 --- a/Examples/Java/Sources/Model.java +++ b/Examples/Java/Sources/Model.java @@ -87,7 +87,7 @@ public boolean getUidIsSet() { public static class Builder { - @SerializedName("id") private @Nullable String uid; + private @Nullable String uid; private boolean[] _bits = new boolean[1]; diff --git a/Examples/Java/Sources/Pin.java b/Examples/Java/Sources/Pin.java index 5f6530df..c7ab8045 100644 --- a/Examples/Java/Sources/Pin.java +++ b/Examples/Java/Sources/Pin.java @@ -329,23 +329,23 @@ public boolean getVisualSearchAttrsIsSet() { public static class Builder { - @SerializedName("attribution") private @Nullable Map attribution; - @SerializedName("attribution_objects") private @Nullable List attributionObjects; - @SerializedName("board") private @Nullable Board board; - @SerializedName("color") private @Nullable String color; - @SerializedName("counts") private @Nullable Map counts; - @SerializedName("created_at") private @NonNull Date createdAt; - @SerializedName("creator") private @NonNull Map creator; - @SerializedName("description") private @Nullable String description; - @SerializedName("id") private @NonNull String uid; - @SerializedName("image") private @Nullable Image image; - @SerializedName("in_stock") private @Nullable PinInStock inStock; - @SerializedName("link") private @Nullable String link; - @SerializedName("media") private @Nullable Map media; - @SerializedName("note") private @Nullable String note; - @SerializedName("tags") private @Nullable List> tags; - @SerializedName("url") private @Nullable String url; - @SerializedName("visual_search_attrs") private @Nullable Map visualSearchAttrs; + private @Nullable Map attribution; + private @Nullable List attributionObjects; + private @Nullable Board board; + private @Nullable String color; + private @Nullable Map counts; + private @NonNull Date createdAt; + private @NonNull Map creator; + private @Nullable String description; + private @NonNull String uid; + private @Nullable Image image; + private @Nullable PinInStock inStock; + private @Nullable String link; + private @Nullable Map media; + private @Nullable String note; + private @Nullable List> tags; + private @Nullable String url; + private @Nullable Map visualSearchAttrs; private boolean[] _bits = new boolean[17]; diff --git a/Examples/Java/Sources/User.java b/Examples/Java/Sources/User.java index a7f3f70b..008ae858 100644 --- a/Examples/Java/Sources/User.java +++ b/Examples/Java/Sources/User.java @@ -217,16 +217,16 @@ public boolean getUsernameIsSet() { public static class Builder { - @SerializedName("bio") private @Nullable String bio; - @SerializedName("counts") private @Nullable Map counts; - @SerializedName("created_at") private @Nullable Date createdAt; - @SerializedName("email_frequency") private @Nullable UserEmailFrequency emailFrequency; - @SerializedName("first_name") private @Nullable String firstName; - @SerializedName("id") private @Nullable String uid; - @SerializedName("image") private @Nullable Image image; - @SerializedName("last_name") private @Nullable String lastName; - @SerializedName("type") private @Nullable String type; - @SerializedName("username") private @Nullable String username; + private @Nullable String bio; + private @Nullable Map counts; + private @Nullable Date createdAt; + private @Nullable UserEmailFrequency emailFrequency; + private @Nullable String firstName; + private @Nullable String uid; + private @Nullable Image image; + private @Nullable String lastName; + private @Nullable String type; + private @Nullable String username; private boolean[] _bits = new boolean[10]; diff --git a/Examples/Java/Sources/VariableSubtitution.java b/Examples/Java/Sources/VariableSubtitution.java index f42fe38e..1bff4801 100644 --- a/Examples/Java/Sources/VariableSubtitution.java +++ b/Examples/Java/Sources/VariableSubtitution.java @@ -129,10 +129,10 @@ public boolean getNewPropIsSet() { public static class Builder { - @SerializedName("alloc_prop") private @Nullable Integer allocProp; - @SerializedName("copy_prop") private @Nullable Integer copyProp; - @SerializedName("mutable_copy_prop") private @Nullable Integer mutableCopyProp; - @SerializedName("new_prop") private @Nullable Integer newProp; + private @Nullable Integer allocProp; + private @Nullable Integer copyProp; + private @Nullable Integer mutableCopyProp; + private @Nullable Integer newProp; private boolean[] _bits = new boolean[4]; diff --git a/Sources/Core/JavaModelRenderer.swift b/Sources/Core/JavaModelRenderer.swift index 7a77ae8e..3483bdad 100644 --- a/Sources/Core/JavaModelRenderer.swift +++ b/Sources/Core/JavaModelRenderer.swift @@ -217,7 +217,7 @@ public struct JavaModelRenderer: JavaFileRenderer { func renderBuilderProperties(modifiers _: JavaModifier = [.private]) -> [[JavaIR.Property]] { let props = transitiveProperties.map { param, schemaObj in - JavaIR.Property(annotations: [.serializedName(name: param)], modifiers: [.private], type: self.typeFromSchema(param, schemaObj), name: Languages.java.snakeCaseToPropertyName(param), initialValue: "") + JavaIR.Property(annotations: [], modifiers: [.private], type: self.typeFromSchema(param, schemaObj), name: Languages.java.snakeCaseToPropertyName(param), initialValue: "") } let bits = JavaIR.Property(annotations: [], modifiers: [.private], type: "boolean[]", name: "_bits", initialValue: "new boolean[" + String(props.count) + "]")