Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Do not edit the class manually.
*/

package com.adyen.model.transactionwebhooks;
package com.adyen.model.java;

import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.ws.rs.core.GenericType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
* Do not edit the class manually.
*/

package com.adyen.model.transactionwebhooks;
package com.adyen.model.java;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand All @@ -23,9 +25,21 @@ public class Amount {
public static final String JSON_PROPERTY_CURRENCY = "currency";
private String currency;

/** Mark when the attribute has been explicitly set. */
private boolean isSetCurrency = false;

public static final String JSON_PROPERTY_VALUE = "value";
private Long value;

/** Mark when the attribute has been explicitly set. */
private boolean isSetValue = false;

/**
* Sets whether attributes with null values should be explicitly included in the JSON payload.
* Default is false.
*/
@JsonIgnore private boolean includeNullValues = false;

public Amount() {}

/**
Expand All @@ -40,6 +54,7 @@ public Amount() {}
*/
public Amount currency(String currency) {
this.currency = currency;
isSetCurrency = true; // mark as set
return this;
}

Expand Down Expand Up @@ -71,6 +86,7 @@ public String getCurrency() {
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setCurrency(String currency) {
this.currency = currency;
isSetCurrency = true; // mark as set
}

/**
Expand All @@ -83,6 +99,7 @@ public void setCurrency(String currency) {
*/
public Amount value(Long value) {
this.value = value;
isSetValue = true; // mark as set
return this;
}

Expand Down Expand Up @@ -110,6 +127,27 @@ public Long getValue() {
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setValue(Long value) {
this.value = value;
isSetValue = true; // mark as set
}

/**
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
*/
public Amount includeNullValues(boolean includeNullValues) {
this.includeNullValues = includeNullValues;
return this;
}

/** Returns whether null values are explicitly serialized in the JSON payload. */
public boolean isIncludeNullValues() {
return includeNullValues;
}

/**
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
*/
public void setIncludeNullValues(boolean includeNullValues) {
this.includeNullValues = includeNullValues;
}

/** Return true if this Amount object is equal to o. */
Expand All @@ -123,12 +161,14 @@ public boolean equals(Object o) {
}
Amount amount = (Amount) o;
return Objects.equals(this.currency, amount.currency)
&& Objects.equals(this.value, amount.value);
&& Objects.equals(this.isSetCurrency, amount.isSetCurrency)
&& Objects.equals(this.value, amount.value)
&& Objects.equals(this.isSetValue, amount.isSetValue);
}

@Override
public int hashCode() {
return Objects.hash(currency, value);
return Objects.hash(currency, isSetCurrency, value, isSetValue);
}

@Override
Expand All @@ -151,6 +191,33 @@ private String toIndentedString(Object o) {
return o.toString().replace("\n", "\n ");
}

/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonAnyGetter
public Map<String, Object> getExplicitNulls() {
if (!this.includeNullValues) {
return Collections.emptyMap();
}

Map<String, Object> nulls = new HashMap<>();

if (isSetCurrency) {
addIfNull(nulls, JSON_PROPERTY_CURRENCY, this.currency);
}
if (isSetValue) {
addIfNull(nulls, JSON_PROPERTY_VALUE, this.value);
}

return nulls;
}

// add to map when value is null
private void addIfNull(Map<String, Object> map, String key, Object value) {
if (value == null) {
map.put(key, null);
}
}
Comment on lines +214 to +219
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This helper method addIfNull, along with the includeNullValues field and its associated methods (includeNullValues, isIncludeNullValues, setIncludeNullValues), are duplicated across multiple model classes in this PR. This introduces a lot of code duplication, making future maintenance harder.

Consider extracting this common functionality into a shared base class. This would centralize the logic for handling explicit null serialization, improving maintainability and reducing code redundancy. Since this code is auto-generated, this feedback is likely for the team maintaining the code generator.

For example, you could have a base class like this:

public abstract class AbstractAdyenModel {
    @JsonIgnore
    private boolean includeNullValues = false;

    // Using generics for a fluent interface in subclasses
    @SuppressWarnings("unchecked")
    public <T extends AbstractAdyenModel> T includeNullValues(boolean includeNullValues) {
        this.includeNullValues = includeNullValues;
        return (T) this;
    }

    public boolean isIncludeNullValues() {
        return includeNullValues;
    }

    public void setIncludeNullValues(boolean includeNullValues) {
        this.includeNullValues = includeNullValues;
    }

    protected void addIfNull(Map<String, Object> map, String key, Object value) {
        if (value == null) {
            map.put(key, null);
        }
    }

    @JsonInclude(JsonInclude.Include.ALWAYS)
    @JsonAnyGetter
    public abstract Map<String, Object> getExplicitNulls();
}

Then, model classes like Amount could extend AbstractAdyenModel and override getExplicitNulls().


/**
* Create an instance of Amount given an JSON string
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
* Do not edit the class manually.
*/

package com.adyen.model.transactionwebhooks;
package com.adyen.model.java;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand All @@ -23,6 +25,15 @@ public class BalancePlatformNotificationResponse {
public static final String JSON_PROPERTY_NOTIFICATION_RESPONSE = "notificationResponse";
private String notificationResponse;

/** Mark when the attribute has been explicitly set. */
private boolean isSetNotificationResponse = false;

/**
* Sets whether attributes with null values should be explicitly included in the JSON payload.
* Default is false.
*/
@JsonIgnore private boolean includeNullValues = false;

public BalancePlatformNotificationResponse() {}

/**
Expand All @@ -36,6 +47,7 @@ public BalancePlatformNotificationResponse() {}
*/
public BalancePlatformNotificationResponse notificationResponse(String notificationResponse) {
this.notificationResponse = notificationResponse;
isSetNotificationResponse = true; // mark as set
return this;
}

Expand Down Expand Up @@ -63,6 +75,27 @@ public String getNotificationResponse() {
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setNotificationResponse(String notificationResponse) {
this.notificationResponse = notificationResponse;
isSetNotificationResponse = true; // mark as set
}

/**
* Configures whether null values are explicitly serialized in the JSON payload. Default is false.
*/
public BalancePlatformNotificationResponse includeNullValues(boolean includeNullValues) {
this.includeNullValues = includeNullValues;
return this;
}

/** Returns whether null values are explicitly serialized in the JSON payload. */
public boolean isIncludeNullValues() {
return includeNullValues;
}

/**
* Sets whether null values should be explicitly serialized in the JSON payload. Default is false.
*/
public void setIncludeNullValues(boolean includeNullValues) {
this.includeNullValues = includeNullValues;
}

/** Return true if this BalancePlatformNotificationResponse object is equal to o. */
Expand All @@ -77,12 +110,15 @@ public boolean equals(Object o) {
BalancePlatformNotificationResponse balancePlatformNotificationResponse =
(BalancePlatformNotificationResponse) o;
return Objects.equals(
this.notificationResponse, balancePlatformNotificationResponse.notificationResponse);
this.notificationResponse, balancePlatformNotificationResponse.notificationResponse)
&& Objects.equals(
this.isSetNotificationResponse,
balancePlatformNotificationResponse.isSetNotificationResponse);
}

@Override
public int hashCode() {
return Objects.hash(notificationResponse);
return Objects.hash(notificationResponse, isSetNotificationResponse);
}

@Override
Expand All @@ -106,6 +142,30 @@ private String toIndentedString(Object o) {
return o.toString().replace("\n", "\n ");
}

/** Returns a map of properties to be merged into the JSON payload as explicit null values. */
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonAnyGetter
public Map<String, Object> getExplicitNulls() {
if (!this.includeNullValues) {
return Collections.emptyMap();
}

Map<String, Object> nulls = new HashMap<>();

if (isSetNotificationResponse) {
addIfNull(nulls, JSON_PROPERTY_NOTIFICATION_RESPONSE, this.notificationResponse);
}

return nulls;
}

// add to map when value is null
private void addIfNull(Map<String, Object> map, String key, Object value) {
if (value == null) {
map.put(key, null);
}
}

/**
* Create an instance of BalancePlatformNotificationResponse given an JSON string
*
Expand Down
Loading
Loading