diff --git a/pom.xml b/pom.xml
index 4b42845..8825b06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,16 @@
spring-webmvc
5.3.23
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.15.2
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+ 2.15.2
+
diff --git a/src/main/java/city/makeour/moc/MocClient.java b/src/main/java/city/makeour/moc/MocClient.java
index 9fd179b..5b8e738 100644
--- a/src/main/java/city/makeour/moc/MocClient.java
+++ b/src/main/java/city/makeour/moc/MocClient.java
@@ -7,6 +7,11 @@
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClient.ResponseSpec;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.fasterxml.jackson.core.type.TypeReference;
+
import city.makeour.moc.ngsiv2.Ngsiv2Client;
import city.makeour.ngsi.v2.api.EntitiesApi;
import city.makeour.ngsi.v2.invoker.ApiClient;
@@ -149,22 +154,21 @@ public ResponseSpec getEntity(String entityId, String type) {
return this.entities().retrieveEntityWithResponseSpec(entityId, type, null, null, "keyValues");
}
+ // Map版(メインロジック)
public ResponseSpec updateEntity(String id, String type, Map attributesToUpdate) {
if (id == null || id.isBlank()) throw new IllegalArgumentException("id is required");
if (type == null || type.isBlank()) throw new IllegalArgumentException("type is required");
if (attributesToUpdate == null) attributesToUpdate = java.util.Collections.emptyMap();
-
+
try {
- // Existence check
this.entities()
.retrieveEntityWithResponseSpec(id, type, null, null, "keyValues")
.toEntity(Object.class);
- // Exists -> POST (keyValues 形式でそのまま送る)
return this.client.updateEntityAttributes(
id,
"application/json",
- attributesToUpdate, // Object(Map) をそのまま PATCH
+ attributesToUpdate,
type,
"keyValues"
);
@@ -172,7 +176,6 @@ public ResponseSpec updateEntity(String id, String type, Map att
} catch (org.springframework.web.client.RestClientResponseException e) {
if (e.getStatusCode().value() != 404) throw e;
- // Not found -> create (従来通り)
java.util.Map body = new java.util.HashMap<>();
body.put("id", id);
body.put("type", type);
@@ -181,22 +184,17 @@ public ResponseSpec updateEntity(String id, String type, Map att
}
}
- // 指定された ID と Type を持つEntityを削除
- public ResponseSpec deleteEntity(String entityId, String type) {
- if (entityId == null || entityId.isBlank()) {
- throw new IllegalArgumentException("id is required");
- }
- // EntitiesApi に定義されている removeEntityWithResponseSpec を呼び出す
- return this.entities().removeEntityWithResponseSpec(entityId, type);
- }
-
- // 指定された ID を持つEntityを削除
- public ResponseSpec deleteEntity(String entityId) {
- return this.deleteEntity(entityId, null);
+ // Object版(Mapに変換してMap版に委譲)
+ public ResponseSpec updateEntity(String id, String type, Object o) {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.registerModule(new JavaTimeModule());
+ mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+
+ Map m = mapper.convertValue(o, new TypeReference