fix #1 migrate codebase to Jackson 3.x
Build and Analyse / build-and-analyse (push) Successful in 50s

This commit is contained in:
2026-08-05 17:42:04 +02:00
parent 36d44ed7a4
commit 42e06245e1
5 changed files with 22 additions and 26 deletions
+1
View File
@@ -3,6 +3,7 @@
- 0.5.0-SNAPSHOT: - 0.5.0-SNAPSHOT:
- moved the project to git.mein-gateway.de - moved the project to git.mein-gateway.de
- replaced sonarqube with own actions - replaced sonarqube with own actions
- migrate to jackson 3.x
- 0.4.0: - 0.4.0:
- fixed some paging issues - fixed some paging issues
- **Breaking Change**: renamed `client.zone().record()` to `client.zone().getRecord()` - **Breaking Change**: renamed `client.zone().record()` to `client.zone().getRecord()`
+2 -7
View File
@@ -36,7 +36,7 @@
<linkXRef>false</linkXRef> <linkXRef>false</linkXRef>
<!-- 3rd party dependencies --> <!-- 3rd party dependencies -->
<jackson.version>2.22.1</jackson.version> <jackson.version>3.2.1</jackson.version>
<httpclient5.version>5.6.2</httpclient5.version> <httpclient5.version>5.6.2</httpclient5.version>
<lombok.version>1.18.46</lombok.version> <lombok.version>1.18.46</lombok.version>
<slf4j.version>2.0.18</slf4j.version> <slf4j.version>2.0.18</slf4j.version>
@@ -95,15 +95,10 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version> <version>${jackson.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
@@ -1,8 +1,6 @@
package codes.thischwa.cf; package codes.thischwa.cf;
import codes.thischwa.cf.model.AbstractResponse; import codes.thischwa.cf.model.AbstractResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.hc.client5.http.classic.methods.HttpDelete; import org.apache.hc.client5.http.classic.methods.HttpDelete;
@@ -20,6 +18,8 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest; import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
/** /**
* Abstract base class for creating HTTP clients to interact with the Cloudflare API. Provides * Abstract base class for creating HTTP clients to interact with the Cloudflare API. Provides
@@ -96,7 +96,7 @@ abstract class CfBasicHttpClient {
throw new CloudflareApiException( throw new CloudflareApiException(
request.getMethod() + " request failed with status code: " + result.statusCode); request.getMethod() + " request failed with status code: " + result.statusCode);
} }
} catch (JsonProcessingException e) { } catch (JacksonException e) {
log.error("JSON parsing error for request to {}", logUri, e); log.error("JSON parsing error for request to {}", logUri, e);
throw new CloudflareApiException("Error processing JSON response", e); throw new CloudflareApiException("Error processing JSON response", e);
} catch (Exception e) { } catch (Exception e) {
@@ -182,7 +182,7 @@ abstract class CfBasicHttpClient {
log.trace("Request methode [{}] payload: {}", request.getMethod(), jsonPayload); log.trace("Request methode [{}] payload: {}", request.getMethod(), jsonPayload);
request.setEntity(new StringEntity(jsonPayload, request.setEntity(new StringEntity(jsonPayload,
ContentType.APPLICATION_JSON)); ContentType.APPLICATION_JSON));
} catch (JsonProcessingException e) { } catch (JacksonException e) {
throw new CloudflareApiException("Error serializing JSON payload", e); throw new CloudflareApiException("Error serializing JSON payload", e);
} }
} }
+10 -10
View File
@@ -1,10 +1,10 @@
package codes.thischwa.cf; package codes.thischwa.cf;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature; import tools.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import tools.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies; import tools.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import tools.jackson.databind.json.JsonMapper;
/** /**
* The JsonConf class provides a utility method for initializing and configuring a shared * The JsonConf class provides a utility method for initializing and configuring a shared
@@ -16,11 +16,11 @@ class JsonConf {
} }
static ObjectMapper initObjectMapper() { static ObjectMapper initObjectMapper() {
ObjectMapper mapper = new ObjectMapper(); return JsonMapper.builder()
mapper.registerModule(new JavaTimeModule()); .changeDefaultPropertyInclusion(
mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL); incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL))
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); .propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
return mapper; .build();
} }
} }
@@ -11,18 +11,18 @@ import codes.thischwa.cf.model.RecordMultipleResponse;
import codes.thischwa.cf.model.RecordSingleResponse; import codes.thischwa.cf.model.RecordSingleResponse;
import codes.thischwa.cf.model.ResponseResultInfo; import codes.thischwa.cf.model.ResponseResultInfo;
import codes.thischwa.cf.model.ZoneMultipleResponse; import codes.thischwa.cf.model.ZoneMultipleResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
public class ObjectMapperTest { public class ObjectMapperTest {
private final ObjectMapper mapper = JsonConf.initObjectMapper(); private final ObjectMapper mapper = JsonConf.initObjectMapper();
@Test @Test
void testObjectMapper() throws IOException { void testObjectMapper() {
ZoneMultipleResponse resp = ZoneMultipleResponse resp =
mapper.readValue(this.getClass().getResourceAsStream("/zone-list-response.json"), mapper.readValue(this.getClass().getResourceAsStream("/zone-list-response.json"),
ZoneMultipleResponse.class); ZoneMultipleResponse.class);
@@ -30,7 +30,7 @@ public class ObjectMapperTest {
} }
@Test @Test
void testErrorResponse() throws IOException { void testErrorResponse() {
List<Class<? extends AbstractResponse>> respClasses = List<Class<? extends AbstractResponse>> respClasses =
List.of(RecordSingleResponse.class, RecordMultipleResponse.class, ZoneMultipleResponse.class, BatchResponse.class); List.of(RecordSingleResponse.class, RecordMultipleResponse.class, ZoneMultipleResponse.class, BatchResponse.class);
respClasses.forEach(this::assertErrorResponse); respClasses.forEach(this::assertErrorResponse);
@@ -46,7 +46,7 @@ public class ObjectMapperTest {
assertFalse(resultInfo.isSuccess()); assertFalse(resultInfo.isSuccess());
assertEquals(1, resultInfo.getErrors().size()); assertEquals(1, resultInfo.getErrors().size());
assertEquals(81053, resultInfo.getErrors().get(0).getCode()); assertEquals(81053, resultInfo.getErrors().get(0).getCode());
} catch (IOException e) { } catch (JacksonException e) {
fail("fail for " + clazz + ": " + e.getMessage()); fail("fail for " + clazz + ": " + e.getMessage());
} }
} }