From b4b745ab096646db09b774c0b1afeef7d150a904 Mon Sep 17 00:00:00 2001
From: loong10k <20489781+loong10k@users.noreply.github.com>
Date: Wed, 4 Nov 2026 03:02:57 +0800
Subject: [PATCH] fix: preserve Jackson 2.22 maintenance compatibility
---
pom.xml | 2 +-
.../spring/boot/JacksonCompatibilityTest.java | 43 +++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 src/test/java/com/faceplusplus/spring/boot/JacksonCompatibilityTest.java
diff --git a/pom.xml b/pom.xml
index 6641942..970960c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
3.20.0
2.0.62
33.8.0-jre
- 2.18.12
+ 2.22.4
6.1.0
1.18.46
4.9.3
diff --git a/src/test/java/com/faceplusplus/spring/boot/JacksonCompatibilityTest.java b/src/test/java/com/faceplusplus/spring/boot/JacksonCompatibilityTest.java
new file mode 100644
index 0000000..68af7e7
--- /dev/null
+++ b/src/test/java/com/faceplusplus/spring/boot/JacksonCompatibilityTest.java
@@ -0,0 +1,43 @@
+package com.faceplusplus.spring.boot;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.faceplusplus.spring.boot.resp.FaceppResponse;
+import okhttp3.*;
+import okio.Buffer;
+import org.junit.jupiter.api.Test;
+import java.util.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+class JacksonCompatibilityTest {
+ @Test void serializesNestedRequestThroughHttpTemplate() throws Exception {
+ ObjectMapper mapper = new ObjectMapper();
+ Map body = new LinkedHashMap<>();
+ body.put("label", "人脸\n\"test\"");
+ body.put("options", Arrays.asList(true, null, 1234567890123L));
+ OkHttpClient client = new OkHttpClient.Builder().addInterceptor(chain -> {
+ Buffer bytes = new Buffer();
+ chain.request().body().writeTo(bytes);
+ JsonNode json = mapper.readTree(bytes.readUtf8());
+ assertEquals("人脸\n\"test\"", json.get("label").asText());
+ assertTrue(json.get("options").get(0).asBoolean());
+ assertTrue(json.get("options").get(1).isNull());
+ assertEquals(1234567890123L, json.get("options").get(2).asLong());
+ return new Response.Builder().request(chain.request()).protocol(Protocol.HTTP_1_1)
+ .code(200).message("OK").body(ResponseBody.create(MediaType.parse("application/json"), "{}" )).build();
+ }).build();
+ FaceppOkHttp3Template template = new FaceppOkHttp3Template(client, mapper, new FaceppProperties());
+ assertSame(mapper, template.getObjectMapper());
+ assertEquals(200, template.post("http://localhost/test", null, null, body, FaceppResponse.class).getCode());
+ }
+
+ @Test void preservesSdkResponseJacksonAnnotations() throws Exception {
+ ObjectMapper mapper = new ObjectMapper();
+ FaceppResponse response = mapper.readValue("{\"code\":200,\"time_used\":17,\"request_id\":\"local\"}", FaceppResponse.class);
+ assertEquals(17, response.getTimeUsed());
+ assertEquals("local", response.getRequestId());
+ JsonNode json = mapper.readTree(mapper.writeValueAsString(response));
+ assertEquals("local", json.get("request_id").asText());
+ assertFalse(json.has("error_message"));
+ }
+}