Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 35 additions & 0 deletions Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void main(String[] args) throws Exception {
apiKeyV1.setApiKey(System.getenv("TALON_API_KEY"));

IntegrationApi iApi = new IntegrationApi(apiClient);
verifyProfileAttributeCanBeCleared(iApi);

// Creating a cart item object
CartItem cartItem = new CartItem();
Expand Down Expand Up @@ -84,4 +85,38 @@ public static void main(String[] args) throws Exception {
}
}
}

private static void verifyProfileAttributeCanBeCleared(IntegrationApi iApi) throws Exception {
// Regression for issue #30: clearing an attribute must remove its previously stored value.
String profileId = "java-sdk-null-attribute-" + UUID.randomUUID();
String attributeName = "Name"; // Built-in customer profile attribute; no custom setup needed.
String initialValue = "Java SDK null attribute regression";
Map<String, Object> attributes = new LinkedHashMap<>();
attributes.put(attributeName, initialValue);
iApi.updateCustomerProfileV2(profileId,
new CustomerProfileIntegrationRequestV2().attributes(attributes), false, null, null);

CustomerProfile before = iApi.getCustomerInventory(
profileId, true, false, false, false, false, false, false).getProfile();
if (before == null || before.getAttributes() == null
|| !initialValue.equals(before.getAttributes().get(attributeName))) {
throw new IllegalStateException("Profile attribute was not stored before clearing it");
}

attributes.put(attributeName, null);
iApi.updateCustomerProfileV2(profileId,
new CustomerProfileIntegrationRequestV2().attributes(attributes), false, null, null);

CustomerProfile after = iApi.getCustomerInventory(
profileId, true, false, false, false, false, false, false).getProfile();
if (after == null) {
throw new IllegalStateException("Customer profile was not returned after clearing its attribute");
}
// Cleared attributes are removed from the stored map, so get() must return null.
if (after.getAttributes() != null && after.getAttributes().get(attributeName) != null) {
throw new IllegalStateException("Profile attribute still has a value after being set to null: "
+ after.getAttributes().get(attributeName));
}
System.out.println("Profile attribute successfully cleared: " + profileId);
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: clean
maven:latest\
/bin/bash -c "mvn clean install && \
mkdir $(INSTALL) && \
cp ~/.m2/repository/one/talon/talon-one-client/maven-metadata-local.xml $(INSTALL)/ && \
cp ~/.m2/repository/one/talon/talon-one-client/maven-metadata-local.xml $(INSTALL)/maven-metadata.xml && \
cp -r ~/.m2/repository/one/talon/talon-one-client/$(VERSION) $(INSTALL)/$(VERSION)"

bundle:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>one.talon</groupId>
<artifactId>talon-one-client</artifactId>
<version>26.21.0</version>
<version>26.21.1</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -52,7 +52,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
compile "one.talon:talon-one-client:26.21.0"
compile "one.talon:talon-one-client:26.21.1"
```

### Others
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'java'
apply plugin: 'com.diffplug.spotless'

group = 'one.talon'
version = '26.21.0'
version = '26.21.1'

buildscript {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
settings(
organization := "one.talon",
name := "talon-one-client",
version := "26.21.0",
version := "26.21.1",
scalaVersion := "2.13.6",
scalacOptions ++= Seq("-feature"),
compile / javacOptions ++= Seq("-Xlint:deprecation"),
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>talon-one-client</artifactId>
<packaging>jar</packaging>
<name>talon-one-client</name>
<version>26.21.0</version>
<version>26.21.1</version>
<url>https://github.com/talon-one/talon-one-maven-artifacts</url>
<description>Talon.One unified JAVA SDK. It allows for programmatic access to the integration and management API with their respective authentication strategies</description>
<scm>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/one/talon/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected void init() {
json = new JSON();

// Set default User-Agent.
setUserAgent("OpenAPI-Generator/26.21.0/java");
setUserAgent("OpenAPI-Generator/26.21.1/java");

authentications = new HashMap<String, Authentication>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/one/talon/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0")
public class Configuration {
public static final String VERSION = "26.21.0";
public static final String VERSION = "26.21.1";

private static final AtomicReference<ApiClient> defaultApiClient = new AtomicReference<>();
private static volatile Supplier<ApiClient> apiClientFactory = ApiClient::new;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/one/talon/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ public Class<? extends one.talon.model.WebhookAuthenticationBase> getClassForEle
}
})
;
GsonBuilder builder = fireBuilder.createGsonBuilder();
// Keep nulls through GsonFire's intermediate JSON trees. Model adapters remove
// unset null properties before writing, so this does not emit untouched fields.
GsonBuilder builder = fireBuilder.createGsonBuilder().serializeNulls();
return builder;
}

Expand Down
56 changes: 36 additions & 20 deletions src/main/java/one/talon/model/APIError.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0")
public class APIError {
// Gson ignores transient state; only setters and JSON input mark properties as present.
private transient Set<String> openapiExplicitlySetFields = new HashSet<>();

public static final String SERIALIZED_NAME_TITLE = "title";
@SerializedName(SERIALIZED_NAME_TITLE)
@javax.annotation.Nonnull
Expand All @@ -72,6 +75,7 @@ public APIError() {

public APIError title(@javax.annotation.Nonnull String title) {
this.title = title;
this.markPropertyAsSet(SERIALIZED_NAME_TITLE);
return this;
}

Expand All @@ -86,11 +90,13 @@ public String getTitle() {

public void setTitle(@javax.annotation.Nonnull String title) {
this.title = title;
this.markPropertyAsSet(SERIALIZED_NAME_TITLE);
}


public APIError details(@javax.annotation.Nullable String details) {
this.details = details;
this.markPropertyAsSet(SERIALIZED_NAME_DETAILS);
return this;
}

Expand All @@ -105,11 +111,13 @@ public String getDetails() {

public void setDetails(@javax.annotation.Nullable String details) {
this.details = details;
this.markPropertyAsSet(SERIALIZED_NAME_DETAILS);
}


public APIError source(@javax.annotation.Nonnull ErrorSource source) {
this.source = source;
this.markPropertyAsSet(SERIALIZED_NAME_SOURCE);
return this;
}

Expand All @@ -124,6 +132,7 @@ public ErrorSource getSource() {

public void setSource(@javax.annotation.Nonnull ErrorSource source) {
this.source = source;
this.markPropertyAsSet(SERIALIZED_NAME_SOURCE);
}

/**
Expand Down Expand Up @@ -171,6 +180,21 @@ public Object getAdditionalProperty(String key) {
return this.additionalProperties.get(key);
}

/** Omit null properties unless they were explicitly assigned or present in JSON input. */
protected final void removeUnsetNullFields(JsonObject obj) {
obj.entrySet().removeIf(entry -> entry.getValue().isJsonNull()
&& !openapiExplicitlySetFields.contains(entry.getKey()));
}

protected final void markPropertyAsSet(String propertyName) {
openapiExplicitlySetFields.add(propertyName);
}

/** Gson populates fields directly, bypassing setters during deserialization. */
protected final void markPropertiesAsSet(Set<String> propertyNames) {
openapiExplicitlySetFields.addAll(propertyNames);
}


@Override
public boolean equals(Object o) {
Expand Down Expand Up @@ -259,7 +283,7 @@ public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!APIError.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'APIError' and its subtypes
return null; // let other model factories handle this type
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<APIError> thisAdapter
Expand All @@ -269,31 +293,22 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
@Override
public void write(JsonWriter out, APIError value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
value.removeUnsetNullFields(obj);
obj.remove("additionalProperties");
// serialize additional properties
if (value.getAdditionalProperties() != null) {
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(entry.getKey(), (Character) entry.getValue());
else {
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
if (jsonElement.isJsonNull()) {
obj.add(entry.getKey(), JsonNull.INSTANCE);
} else if (jsonElement.isJsonArray()) {
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
} else {
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
}
}
// TypeAdapter.toJsonTree keeps explicit null entries in arbitrary maps too.
obj.add(entry.getKey(), gson.getAdapter(Object.class).toJsonTree(entry.getValue()));
}
}
elementAdapter.write(out, obj);
boolean originalSerializeNulls = out.getSerializeNulls();
try {
out.setSerializeNulls(true);
elementAdapter.write(out, obj);
} finally {
out.setSerializeNulls(originalSerializeNulls);
}
}

@Override
Expand All @@ -303,6 +318,7 @@ public APIError read(JsonReader in) throws IOException {
JsonObject jsonObj = jsonElement.getAsJsonObject();
// store additional fields in the deserialized instance
APIError instance = thisAdapter.fromJsonTree(jsonObj);
instance.markPropertiesAsSet(jsonObj.keySet());
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
if (!openapiFields.contains(entry.getKey())) {
if (entry.getValue().isJsonPrimitive()) { // primitive type
Expand Down
52 changes: 32 additions & 20 deletions src/main/java/one/talon/model/AcceptCouponEffectProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0")
public class AcceptCouponEffectProps {
// Gson ignores transient state; only setters and JSON input mark properties as present.
private transient Set<String> openapiExplicitlySetFields = new HashSet<>();

public static final String SERIALIZED_NAME_VALUE = "value";
@SerializedName(SERIALIZED_NAME_VALUE)
@javax.annotation.Nonnull
Expand All @@ -61,6 +64,7 @@ public AcceptCouponEffectProps() {

public AcceptCouponEffectProps value(@javax.annotation.Nonnull String value) {
this.value = value;
this.markPropertyAsSet(SERIALIZED_NAME_VALUE);
return this;
}

Expand All @@ -75,6 +79,7 @@ public String getValue() {

public void setValue(@javax.annotation.Nonnull String value) {
this.value = value;
this.markPropertyAsSet(SERIALIZED_NAME_VALUE);
}

/**
Expand Down Expand Up @@ -122,6 +127,21 @@ public Object getAdditionalProperty(String key) {
return this.additionalProperties.get(key);
}

/** Omit null properties unless they were explicitly assigned or present in JSON input. */
protected final void removeUnsetNullFields(JsonObject obj) {
obj.entrySet().removeIf(entry -> entry.getValue().isJsonNull()
&& !openapiExplicitlySetFields.contains(entry.getKey()));
}

protected final void markPropertyAsSet(String propertyName) {
openapiExplicitlySetFields.add(propertyName);
}

/** Gson populates fields directly, bypassing setters during deserialization. */
protected final void markPropertiesAsSet(Set<String> propertyNames) {
openapiExplicitlySetFields.addAll(propertyNames);
}


@Override
public boolean equals(Object o) {
Expand Down Expand Up @@ -201,7 +221,7 @@ public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AcceptCouponEffectProps.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AcceptCouponEffectProps' and its subtypes
return null; // let other model factories handle this type
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AcceptCouponEffectProps> thisAdapter
Expand All @@ -211,31 +231,22 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
@Override
public void write(JsonWriter out, AcceptCouponEffectProps value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
value.removeUnsetNullFields(obj);
obj.remove("additionalProperties");
// serialize additional properties
if (value.getAdditionalProperties() != null) {
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(entry.getKey(), (Character) entry.getValue());
else {
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
if (jsonElement.isJsonNull()) {
obj.add(entry.getKey(), JsonNull.INSTANCE);
} else if (jsonElement.isJsonArray()) {
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
} else {
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
}
}
// TypeAdapter.toJsonTree keeps explicit null entries in arbitrary maps too.
obj.add(entry.getKey(), gson.getAdapter(Object.class).toJsonTree(entry.getValue()));
}
}
elementAdapter.write(out, obj);
boolean originalSerializeNulls = out.getSerializeNulls();
try {
out.setSerializeNulls(true);
elementAdapter.write(out, obj);
} finally {
out.setSerializeNulls(originalSerializeNulls);
}
}

@Override
Expand All @@ -245,6 +256,7 @@ public AcceptCouponEffectProps read(JsonReader in) throws IOException {
JsonObject jsonObj = jsonElement.getAsJsonObject();
// store additional fields in the deserialized instance
AcceptCouponEffectProps instance = thisAdapter.fromJsonTree(jsonObj);
instance.markPropertiesAsSet(jsonObj.keySet());
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
if (!openapiFields.contains(entry.getKey())) {
if (entry.getValue().isJsonPrimitive()) { // primitive type
Expand Down
Loading
Loading