Skip to content

Commit dbbaa4b

Browse files
authored
Handle nullable properties (#1603)
* Update Mustache templates * Generate Management API models * Correct Mustache template (chain method) * Generate Management API after correcting templates * Add tests * Generate all models to use latest OpenAPI spec * Add missing test * Add test testToJsonFlagTrueButFieldNotSet
1 parent 79de0a3 commit dbbaa4b

File tree

206 files changed

+18986
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+18986
-153
lines changed

src/main/java/com/adyen/model/management/AccelInfo.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
package com.adyen.model.management;
1313

14+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
1415
import com.fasterxml.jackson.annotation.JsonCreator;
16+
import com.fasterxml.jackson.annotation.JsonIgnore;
1517
import com.fasterxml.jackson.annotation.JsonInclude;
1618
import com.fasterxml.jackson.annotation.JsonProperty;
1719
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -80,9 +82,21 @@ public static ProcessingTypeEnum fromValue(String value) {
8082
public static final String JSON_PROPERTY_PROCESSING_TYPE = "processingType";
8183
private ProcessingTypeEnum processingType;
8284

85+
/** Mark when the attribute has been explicitly set. */
86+
private boolean isSetProcessingType = false;
87+
8388
public static final String JSON_PROPERTY_TRANSACTION_DESCRIPTION = "transactionDescription";
8489
private TransactionDescriptionInfo transactionDescription;
8590

91+
/** Mark when the attribute has been explicitly set. */
92+
private boolean isSetTransactionDescription = false;
93+
94+
/**
95+
* Sets whether attributes with null values should be explicitly included in the JSON payload.
96+
* Default is false.
97+
*/
98+
@JsonIgnore private boolean includeNullValues = false;
99+
86100
public AccelInfo() {}
87101

88102
/**
@@ -103,6 +117,7 @@ public AccelInfo() {}
103117
*/
104118
public AccelInfo processingType(ProcessingTypeEnum processingType) {
105119
this.processingType = processingType;
120+
isSetProcessingType = true; // mark as set
106121
return this;
107122
}
108123

@@ -146,6 +161,7 @@ public ProcessingTypeEnum getProcessingType() {
146161
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
147162
public void setProcessingType(ProcessingTypeEnum processingType) {
148163
this.processingType = processingType;
164+
isSetProcessingType = true; // mark as set
149165
}
150166

151167
/**
@@ -156,6 +172,7 @@ public void setProcessingType(ProcessingTypeEnum processingType) {
156172
*/
157173
public AccelInfo transactionDescription(TransactionDescriptionInfo transactionDescription) {
158174
this.transactionDescription = transactionDescription;
175+
isSetTransactionDescription = true; // mark as set
159176
return this;
160177
}
161178

@@ -179,6 +196,27 @@ public TransactionDescriptionInfo getTransactionDescription() {
179196
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
180197
public void setTransactionDescription(TransactionDescriptionInfo transactionDescription) {
181198
this.transactionDescription = transactionDescription;
199+
isSetTransactionDescription = true; // mark as set
200+
}
201+
202+
/**
203+
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
204+
*/
205+
public AccelInfo includeNullValues(boolean includeNullValues) {
206+
this.includeNullValues = includeNullValues;
207+
return this;
208+
}
209+
210+
/** Returns whether null values are explicitly serialized in the JSON payload. */
211+
public boolean isIncludeNullValues() {
212+
return includeNullValues;
213+
}
214+
215+
/**
216+
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
217+
*/
218+
public void setIncludeNullValues(boolean includeNullValues) {
219+
this.includeNullValues = includeNullValues;
182220
}
183221

184222
/** Return true if this AccelInfo object is equal to o. */
@@ -222,6 +260,33 @@ private String toIndentedString(Object o) {
222260
return o.toString().replace("\n", "\n ");
223261
}
224262

263+
/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
264+
@JsonInclude(JsonInclude.Include.ALWAYS)
265+
@JsonAnyGetter
266+
public Map<String, Object> getExplicitNulls() {
267+
if (!this.includeNullValues) {
268+
return Collections.emptyMap();
269+
}
270+
271+
Map<String, Object> nulls = new HashMap<>();
272+
273+
if (isSetProcessingType) {
274+
addIfNull(nulls, JSON_PROPERTY_PROCESSING_TYPE, this.processingType);
275+
}
276+
if (isSetTransactionDescription) {
277+
addIfNull(nulls, JSON_PROPERTY_TRANSACTION_DESCRIPTION, this.transactionDescription);
278+
}
279+
280+
return nulls;
281+
}
282+
283+
// add to map when value is null
284+
private void addIfNull(Map<String, Object> map, String key, Object value) {
285+
if (value == null) {
286+
map.put(key, null);
287+
}
288+
}
289+
225290
/**
226291
* Create an instance of AccelInfo given an JSON string
227292
*

src/main/java/com/adyen/model/management/AdditionalCommission.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
package com.adyen.model.management;
1313

14+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
15+
import com.fasterxml.jackson.annotation.JsonIgnore;
1416
import com.fasterxml.jackson.annotation.JsonInclude;
1517
import com.fasterxml.jackson.annotation.JsonProperty;
1618
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -27,12 +29,27 @@ public class AdditionalCommission {
2729
public static final String JSON_PROPERTY_BALANCE_ACCOUNT_ID = "balanceAccountId";
2830
private String balanceAccountId;
2931

32+
/** Mark when the attribute has been explicitly set. */
33+
private boolean isSetBalanceAccountId = false;
34+
3035
public static final String JSON_PROPERTY_FIXED_AMOUNT = "fixedAmount";
3136
private Long fixedAmount;
3237

38+
/** Mark when the attribute has been explicitly set. */
39+
private boolean isSetFixedAmount = false;
40+
3341
public static final String JSON_PROPERTY_VARIABLE_PERCENTAGE = "variablePercentage";
3442
private Long variablePercentage;
3543

44+
/** Mark when the attribute has been explicitly set. */
45+
private boolean isSetVariablePercentage = false;
46+
47+
/**
48+
* Sets whether attributes with null values should be explicitly included in the JSON payload.
49+
* Default is false.
50+
*/
51+
@JsonIgnore private boolean includeNullValues = false;
52+
3653
public AdditionalCommission() {}
3754

3855
/**
@@ -44,6 +61,7 @@ public AdditionalCommission() {}
4461
*/
4562
public AdditionalCommission balanceAccountId(String balanceAccountId) {
4663
this.balanceAccountId = balanceAccountId;
64+
isSetBalanceAccountId = true; // mark as set
4765
return this;
4866
}
4967

@@ -69,6 +87,7 @@ public String getBalanceAccountId() {
6987
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
7088
public void setBalanceAccountId(String balanceAccountId) {
7189
this.balanceAccountId = balanceAccountId;
90+
isSetBalanceAccountId = true; // mark as set
7291
}
7392

7493
/**
@@ -79,6 +98,7 @@ public void setBalanceAccountId(String balanceAccountId) {
7998
*/
8099
public AdditionalCommission fixedAmount(Long fixedAmount) {
81100
this.fixedAmount = fixedAmount;
101+
isSetFixedAmount = true; // mark as set
82102
return this;
83103
}
84104

@@ -102,6 +122,7 @@ public Long getFixedAmount() {
102122
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
103123
public void setFixedAmount(Long fixedAmount) {
104124
this.fixedAmount = fixedAmount;
125+
isSetFixedAmount = true; // mark as set
105126
}
106127

107128
/**
@@ -112,6 +133,7 @@ public void setFixedAmount(Long fixedAmount) {
112133
*/
113134
public AdditionalCommission variablePercentage(Long variablePercentage) {
114135
this.variablePercentage = variablePercentage;
136+
isSetVariablePercentage = true; // mark as set
115137
return this;
116138
}
117139

@@ -135,6 +157,27 @@ public Long getVariablePercentage() {
135157
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
136158
public void setVariablePercentage(Long variablePercentage) {
137159
this.variablePercentage = variablePercentage;
160+
isSetVariablePercentage = true; // mark as set
161+
}
162+
163+
/**
164+
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
165+
*/
166+
public AdditionalCommission includeNullValues(boolean includeNullValues) {
167+
this.includeNullValues = includeNullValues;
168+
return this;
169+
}
170+
171+
/** Returns whether null values are explicitly serialized in the JSON payload. */
172+
public boolean isIncludeNullValues() {
173+
return includeNullValues;
174+
}
175+
176+
/**
177+
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
178+
*/
179+
public void setIncludeNullValues(boolean includeNullValues) {
180+
this.includeNullValues = includeNullValues;
138181
}
139182

140183
/** Return true if this AdditionalCommission object is equal to o. */
@@ -178,6 +221,36 @@ private String toIndentedString(Object o) {
178221
return o.toString().replace("\n", "\n ");
179222
}
180223

224+
/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
225+
@JsonInclude(JsonInclude.Include.ALWAYS)
226+
@JsonAnyGetter
227+
public Map<String, Object> getExplicitNulls() {
228+
if (!this.includeNullValues) {
229+
return Collections.emptyMap();
230+
}
231+
232+
Map<String, Object> nulls = new HashMap<>();
233+
234+
if (isSetBalanceAccountId) {
235+
addIfNull(nulls, JSON_PROPERTY_BALANCE_ACCOUNT_ID, this.balanceAccountId);
236+
}
237+
if (isSetFixedAmount) {
238+
addIfNull(nulls, JSON_PROPERTY_FIXED_AMOUNT, this.fixedAmount);
239+
}
240+
if (isSetVariablePercentage) {
241+
addIfNull(nulls, JSON_PROPERTY_VARIABLE_PERCENTAGE, this.variablePercentage);
242+
}
243+
244+
return nulls;
245+
}
246+
247+
// add to map when value is null
248+
private void addIfNull(Map<String, Object> map, String key, Object value) {
249+
if (value == null) {
250+
map.put(key, null);
251+
}
252+
}
253+
181254
/**
182255
* Create an instance of AdditionalCommission given an JSON string
183256
*

src/main/java/com/adyen/model/management/AdditionalSettings.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
package com.adyen.model.management;
1313

14+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
15+
import com.fasterxml.jackson.annotation.JsonIgnore;
1416
import com.fasterxml.jackson.annotation.JsonInclude;
1517
import com.fasterxml.jackson.annotation.JsonProperty;
1618
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -30,9 +32,21 @@ public class AdditionalSettings {
3032
public static final String JSON_PROPERTY_INCLUDE_EVENT_CODES = "includeEventCodes";
3133
private List<String> includeEventCodes;
3234

35+
/** Mark when the attribute has been explicitly set. */
36+
private boolean isSetIncludeEventCodes = false;
37+
3338
public static final String JSON_PROPERTY_PROPERTIES = "properties";
3439
private Map<String, Boolean> properties;
3540

41+
/** Mark when the attribute has been explicitly set. */
42+
private boolean isSetProperties = false;
43+
44+
/**
45+
* Sets whether attributes with null values should be explicitly included in the JSON payload.
46+
* Default is false.
47+
*/
48+
@JsonIgnore private boolean includeNullValues = false;
49+
3650
public AdditionalSettings() {}
3751

3852
/**
@@ -44,6 +58,7 @@ public AdditionalSettings() {}
4458
*/
4559
public AdditionalSettings includeEventCodes(List<String> includeEventCodes) {
4660
this.includeEventCodes = includeEventCodes;
61+
isSetIncludeEventCodes = true; // mark as set
4762
return this;
4863
}
4964

@@ -77,6 +92,7 @@ public List<String> getIncludeEventCodes() {
7792
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
7893
public void setIncludeEventCodes(List<String> includeEventCodes) {
7994
this.includeEventCodes = includeEventCodes;
95+
isSetIncludeEventCodes = true; // mark as set
8096
}
8197

8298
/**
@@ -96,6 +112,7 @@ public void setIncludeEventCodes(List<String> includeEventCodes) {
96112
*/
97113
public AdditionalSettings properties(Map<String, Boolean> properties) {
98114
this.properties = properties;
115+
isSetProperties = true; // mark as set
99116
return this;
100117
}
101118

@@ -145,6 +162,27 @@ public Map<String, Boolean> getProperties() {
145162
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
146163
public void setProperties(Map<String, Boolean> properties) {
147164
this.properties = properties;
165+
isSetProperties = true; // mark as set
166+
}
167+
168+
/**
169+
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
170+
*/
171+
public AdditionalSettings includeNullValues(boolean includeNullValues) {
172+
this.includeNullValues = includeNullValues;
173+
return this;
174+
}
175+
176+
/** Returns whether null values are explicitly serialized in the JSON payload. */
177+
public boolean isIncludeNullValues() {
178+
return includeNullValues;
179+
}
180+
181+
/**
182+
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
183+
*/
184+
public void setIncludeNullValues(boolean includeNullValues) {
185+
this.includeNullValues = includeNullValues;
148186
}
149187

150188
/** Return true if this AdditionalSettings object is equal to o. */
@@ -186,6 +224,33 @@ private String toIndentedString(Object o) {
186224
return o.toString().replace("\n", "\n ");
187225
}
188226

227+
/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
228+
@JsonInclude(JsonInclude.Include.ALWAYS)
229+
@JsonAnyGetter
230+
public Map<String, Object> getExplicitNulls() {
231+
if (!this.includeNullValues) {
232+
return Collections.emptyMap();
233+
}
234+
235+
Map<String, Object> nulls = new HashMap<>();
236+
237+
if (isSetIncludeEventCodes) {
238+
addIfNull(nulls, JSON_PROPERTY_INCLUDE_EVENT_CODES, this.includeEventCodes);
239+
}
240+
if (isSetProperties) {
241+
addIfNull(nulls, JSON_PROPERTY_PROPERTIES, this.properties);
242+
}
243+
244+
return nulls;
245+
}
246+
247+
// add to map when value is null
248+
private void addIfNull(Map<String, Object> map, String key, Object value) {
249+
if (value == null) {
250+
map.put(key, null);
251+
}
252+
}
253+
189254
/**
190255
* Create an instance of AdditionalSettings given an JSON string
191256
*

0 commit comments

Comments
 (0)