Skip to content

Commit 0d212d6

Browse files
committed
fix(upsert): allow null values in Map-based updates
Map nulls are now preserved so fields can be explicitly cleared. Entity-based updates still strip nulls via @SbxModel's @JsonInclude.
1 parent a7d437e commit 0d212d6

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Java 21+ client for SBX Cloud APIs. Spring Boot 3.x compatible.
1717
<dependency>
1818
<groupId>com.github.socobox</groupId>
1919
<artifactId>sbxcloud-lib-java</artifactId>
20-
<version>v0.0.15</version>
20+
<version>v0.0.16</version>
2121
</dependency>
2222
```
2323

@@ -29,7 +29,7 @@ repositories {
2929
}
3030
3131
dependencies {
32-
implementation 'com.github.socobox:sbxcloud-lib-java:v0.0.15'
32+
implementation 'com.github.socobox:sbxcloud-lib-java:v0.0.16'
3333
}
3434
```
3535

src/main/java/com/sbxcloud/sbx/annotation/SbxModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
44
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
56
import com.fasterxml.jackson.databind.annotation.JsonNaming;
67
import com.sbxcloud.sbx.jackson.SbxNamingStrategy;
78

@@ -48,6 +49,7 @@
4849
@JacksonAnnotationsInside
4950
@JsonNaming(SbxNamingStrategy.class)
5051
@JsonIgnoreProperties(ignoreUnknown = true)
52+
@JsonInclude(JsonInclude.Include.NON_NULL)
5153
public @interface SbxModel {
5254
/**
5355
* The SBX row_model name.

src/main/java/com/sbxcloud/sbx/client/SBXService.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -916,25 +916,22 @@ private <T> SBXResponse<T> upsert(String endpoint, String model, List<Map<String
916916
/**
917917
* Cleans a row for create/update:
918918
* - Removes _META/meta (read-only)
919-
* - Removes null values (allows partial updates)
919+
* <p>
920+
* Null values are preserved so fields can be explicitly cleared.
921+
* For entity-based updates, nulls are already stripped by @SbxModel's
922+
* {@code @JsonInclude(NON_NULL)} during entity-to-Map conversion.
920923
*/
921924
private Map<String, Object> cleanForUpsert(Map<String, Object> row) {
922925
var cleaned = new LinkedHashMap<String, Object>();
923926
for (var entry : row.entrySet()) {
924927
String key = entry.getKey();
925-
Object value = entry.getValue();
926928

927929
// Skip meta fields (read-only)
928930
if ("_META".equals(key) || "meta".equals(key)) {
929931
continue;
930932
}
931933

932-
// Skip null values (allows partial updates)
933-
if (value == null) {
934-
continue;
935-
}
936-
937-
cleaned.put(key, value);
934+
cleaned.put(key, entry.getValue());
938935
}
939936
return cleaned;
940937
}

src/main/java/com/sbxcloud/sbx/model/SBXUpsertRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Request payload for create/update operations.
1111
*/
12-
@JsonInclude(JsonInclude.Include.NON_NULL)
12+
@JsonInclude(JsonInclude.Include.ALWAYS)
1313
public record SBXUpsertRequest(
1414
@JsonProperty("row_model") String rowModel,
1515
String domain,

0 commit comments

Comments
 (0)