Skip to content

Commit b6b004f

Browse files
authored
Skip Handling of Nullable Properties in Webhooks (#1609)
* Skip handlingNullable code for Webhook models * Generate Recurring models * Fix hashCode and equals implementations * Generate hashCode and equals implementations
1 parent 6f3a5a2 commit b6b004f

26 files changed

+2506
-75
lines changed

src/main/java/com/adyen/model/recurring/Address.java

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

1212
package com.adyen.model.recurring;
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,21 +32,45 @@ public class Address {
3032
public static final String JSON_PROPERTY_CITY = "city";
3133
private String city;
3234

35+
/** Mark when the attribute has been explicitly set. */
36+
private boolean isSetCity = false;
37+
3338
public static final String JSON_PROPERTY_COUNTRY = "country";
3439
private String country;
3540

41+
/** Mark when the attribute has been explicitly set. */
42+
private boolean isSetCountry = false;
43+
3644
public static final String JSON_PROPERTY_HOUSE_NUMBER_OR_NAME = "houseNumberOrName";
3745
private String houseNumberOrName;
3846

47+
/** Mark when the attribute has been explicitly set. */
48+
private boolean isSetHouseNumberOrName = false;
49+
3950
public static final String JSON_PROPERTY_POSTAL_CODE = "postalCode";
4051
private String postalCode;
4152

53+
/** Mark when the attribute has been explicitly set. */
54+
private boolean isSetPostalCode = false;
55+
4256
public static final String JSON_PROPERTY_STATE_OR_PROVINCE = "stateOrProvince";
4357
private String stateOrProvince;
4458

59+
/** Mark when the attribute has been explicitly set. */
60+
private boolean isSetStateOrProvince = false;
61+
4562
public static final String JSON_PROPERTY_STREET = "street";
4663
private String street;
4764

65+
/** Mark when the attribute has been explicitly set. */
66+
private boolean isSetStreet = false;
67+
68+
/**
69+
* Sets whether attributes with null values should be explicitly included in the JSON payload.
70+
* Default is false.
71+
*/
72+
@JsonIgnore private boolean includeNullValues = false;
73+
4874
public Address() {}
4975

5076
/**
@@ -55,6 +81,7 @@ public Address() {}
5581
*/
5682
public Address city(String city) {
5783
this.city = city;
84+
isSetCity = true; // mark as set
5885
return this;
5986
}
6087

@@ -78,6 +105,7 @@ public String getCity() {
78105
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
79106
public void setCity(String city) {
80107
this.city = city;
108+
isSetCity = true; // mark as set
81109
}
82110

83111
/**
@@ -92,6 +120,7 @@ public void setCity(String city) {
92120
*/
93121
public Address country(String country) {
94122
this.country = country;
123+
isSetCountry = true; // mark as set
95124
return this;
96125
}
97126

@@ -123,6 +152,7 @@ public String getCountry() {
123152
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
124153
public void setCountry(String country) {
125154
this.country = country;
155+
isSetCountry = true; // mark as set
126156
}
127157

128158
/**
@@ -133,6 +163,7 @@ public void setCountry(String country) {
133163
*/
134164
public Address houseNumberOrName(String houseNumberOrName) {
135165
this.houseNumberOrName = houseNumberOrName;
166+
isSetHouseNumberOrName = true; // mark as set
136167
return this;
137168
}
138169

@@ -156,6 +187,7 @@ public String getHouseNumberOrName() {
156187
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
157188
public void setHouseNumberOrName(String houseNumberOrName) {
158189
this.houseNumberOrName = houseNumberOrName;
190+
isSetHouseNumberOrName = true; // mark as set
159191
}
160192

161193
/**
@@ -168,6 +200,7 @@ public void setHouseNumberOrName(String houseNumberOrName) {
168200
*/
169201
public Address postalCode(String postalCode) {
170202
this.postalCode = postalCode;
203+
isSetPostalCode = true; // mark as set
171204
return this;
172205
}
173206

@@ -195,6 +228,7 @@ public String getPostalCode() {
195228
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
196229
public void setPostalCode(String postalCode) {
197230
this.postalCode = postalCode;
231+
isSetPostalCode = true; // mark as set
198232
}
199233

200234
/**
@@ -207,6 +241,7 @@ public void setPostalCode(String postalCode) {
207241
*/
208242
public Address stateOrProvince(String stateOrProvince) {
209243
this.stateOrProvince = stateOrProvince;
244+
isSetStateOrProvince = true; // mark as set
210245
return this;
211246
}
212247

@@ -234,6 +269,7 @@ public String getStateOrProvince() {
234269
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
235270
public void setStateOrProvince(String stateOrProvince) {
236271
this.stateOrProvince = stateOrProvince;
272+
isSetStateOrProvince = true; // mark as set
237273
}
238274

239275
/**
@@ -247,6 +283,7 @@ public void setStateOrProvince(String stateOrProvince) {
247283
*/
248284
public Address street(String street) {
249285
this.street = street;
286+
isSetStreet = true; // mark as set
250287
return this;
251288
}
252289

@@ -276,6 +313,27 @@ public String getStreet() {
276313
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
277314
public void setStreet(String street) {
278315
this.street = street;
316+
isSetStreet = true; // mark as set
317+
}
318+
319+
/**
320+
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
321+
*/
322+
public Address includeNullValues(boolean includeNullValues) {
323+
this.includeNullValues = includeNullValues;
324+
return this;
325+
}
326+
327+
/** Returns whether null values are explicitly serialized in the JSON payload. */
328+
public boolean isIncludeNullValues() {
329+
return includeNullValues;
330+
}
331+
332+
/**
333+
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
334+
*/
335+
public void setIncludeNullValues(boolean includeNullValues) {
336+
this.includeNullValues = includeNullValues;
279337
}
280338

281339
/** Return true if this Address object is equal to o. */
@@ -289,16 +347,34 @@ public boolean equals(Object o) {
289347
}
290348
Address address = (Address) o;
291349
return Objects.equals(this.city, address.city)
350+
&& Objects.equals(this.isSetCity, address.isSetCity)
292351
&& Objects.equals(this.country, address.country)
352+
&& Objects.equals(this.isSetCountry, address.isSetCountry)
293353
&& Objects.equals(this.houseNumberOrName, address.houseNumberOrName)
354+
&& Objects.equals(this.isSetHouseNumberOrName, address.isSetHouseNumberOrName)
294355
&& Objects.equals(this.postalCode, address.postalCode)
356+
&& Objects.equals(this.isSetPostalCode, address.isSetPostalCode)
295357
&& Objects.equals(this.stateOrProvince, address.stateOrProvince)
296-
&& Objects.equals(this.street, address.street);
358+
&& Objects.equals(this.isSetStateOrProvince, address.isSetStateOrProvince)
359+
&& Objects.equals(this.street, address.street)
360+
&& Objects.equals(this.isSetStreet, address.isSetStreet);
297361
}
298362

299363
@Override
300364
public int hashCode() {
301-
return Objects.hash(city, country, houseNumberOrName, postalCode, stateOrProvince, street);
365+
return Objects.hash(
366+
city,
367+
isSetCity,
368+
country,
369+
isSetCountry,
370+
houseNumberOrName,
371+
isSetHouseNumberOrName,
372+
postalCode,
373+
isSetPostalCode,
374+
stateOrProvince,
375+
isSetStateOrProvince,
376+
street,
377+
isSetStreet);
302378
}
303379

304380
@Override
@@ -325,6 +401,45 @@ private String toIndentedString(Object o) {
325401
return o.toString().replace("\n", "\n ");
326402
}
327403

404+
/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
405+
@JsonInclude(JsonInclude.Include.ALWAYS)
406+
@JsonAnyGetter
407+
public Map<String, Object> getExplicitNulls() {
408+
if (!this.includeNullValues) {
409+
return Collections.emptyMap();
410+
}
411+
412+
Map<String, Object> nulls = new HashMap<>();
413+
414+
if (isSetCity) {
415+
addIfNull(nulls, JSON_PROPERTY_CITY, this.city);
416+
}
417+
if (isSetCountry) {
418+
addIfNull(nulls, JSON_PROPERTY_COUNTRY, this.country);
419+
}
420+
if (isSetHouseNumberOrName) {
421+
addIfNull(nulls, JSON_PROPERTY_HOUSE_NUMBER_OR_NAME, this.houseNumberOrName);
422+
}
423+
if (isSetPostalCode) {
424+
addIfNull(nulls, JSON_PROPERTY_POSTAL_CODE, this.postalCode);
425+
}
426+
if (isSetStateOrProvince) {
427+
addIfNull(nulls, JSON_PROPERTY_STATE_OR_PROVINCE, this.stateOrProvince);
428+
}
429+
if (isSetStreet) {
430+
addIfNull(nulls, JSON_PROPERTY_STREET, this.street);
431+
}
432+
433+
return nulls;
434+
}
435+
436+
// add to map when value is null
437+
private void addIfNull(Map<String, Object> map, String key, Object value) {
438+
if (value == null) {
439+
map.put(key, null);
440+
}
441+
}
442+
328443
/**
329444
* Create an instance of Address given an JSON string
330445
*

0 commit comments

Comments
 (0)