diff --git a/changelog.md b/changelog.md index abac8be..2562882 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ - 0.5.0-SNAPSHOT: - moved the project to git.mein-gateway.de - replaced sonarqube with own actions + - migrate to jackson 3.x - 0.4.0: - fixed some paging issues - **Breaking Change**: renamed `client.zone().record()` to `client.zone().getRecord()` diff --git a/pom.xml b/pom.xml index 9863de9..1da4dca 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ false - 2.22.1 + 3.2.1 5.6.2 1.18.46 2.0.18 @@ -95,15 +95,10 @@ provided - com.fasterxml.jackson.core + tools.jackson.core jackson-databind ${jackson.version} - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${jackson.version} - org.jetbrains annotations diff --git a/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java b/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java index 6c8c6a4..d1b4edb 100644 --- a/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java +++ b/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java @@ -1,8 +1,6 @@ package codes.thischwa.cf; import codes.thischwa.cf.model.AbstractResponse; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import java.nio.charset.StandardCharsets; import lombok.extern.slf4j.Slf4j; 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.message.BasicClassicHttpRequest; 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 @@ -96,7 +96,7 @@ abstract class CfBasicHttpClient { throw new CloudflareApiException( 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); throw new CloudflareApiException("Error processing JSON response", e); } catch (Exception e) { @@ -182,7 +182,7 @@ abstract class CfBasicHttpClient { log.trace("Request methode [{}] payload: {}", request.getMethod(), jsonPayload); request.setEntity(new StringEntity(jsonPayload, ContentType.APPLICATION_JSON)); - } catch (JsonProcessingException e) { + } catch (JacksonException e) { throw new CloudflareApiException("Error serializing JSON payload", e); } } diff --git a/src/main/java/codes/thischwa/cf/JsonConf.java b/src/main/java/codes/thischwa/cf/JsonConf.java index c9ebbd7..5a6201c 100644 --- a/src/main/java/codes/thischwa/cf/JsonConf.java +++ b/src/main/java/codes/thischwa/cf/JsonConf.java @@ -1,10 +1,10 @@ package codes.thischwa.cf; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import tools.jackson.databind.DeserializationFeature; +import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.PropertyNamingStrategies; +import tools.jackson.databind.json.JsonMapper; /** * The JsonConf class provides a utility method for initializing and configuring a shared @@ -16,11 +16,11 @@ class JsonConf { } static ObjectMapper initObjectMapper() { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JavaTimeModule()); - mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); - return mapper; + return JsonMapper.builder() + .changeDefaultPropertyInclusion( + incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL)) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) + .build(); } } diff --git a/src/test/java/codes/thischwa/cf/ObjectMapperTest.java b/src/test/java/codes/thischwa/cf/ObjectMapperTest.java index 203dda6..529a581 100644 --- a/src/test/java/codes/thischwa/cf/ObjectMapperTest.java +++ b/src/test/java/codes/thischwa/cf/ObjectMapperTest.java @@ -11,18 +11,18 @@ import codes.thischwa.cf.model.RecordMultipleResponse; import codes.thischwa.cf.model.RecordSingleResponse; import codes.thischwa.cf.model.ResponseResultInfo; import codes.thischwa.cf.model.ZoneMultipleResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; import java.io.InputStream; import java.util.List; import org.junit.jupiter.api.Test; +import tools.jackson.core.JacksonException; +import tools.jackson.databind.ObjectMapper; public class ObjectMapperTest { private final ObjectMapper mapper = JsonConf.initObjectMapper(); @Test - void testObjectMapper() throws IOException { + void testObjectMapper() { ZoneMultipleResponse resp = mapper.readValue(this.getClass().getResourceAsStream("/zone-list-response.json"), ZoneMultipleResponse.class); @@ -30,7 +30,7 @@ public class ObjectMapperTest { } @Test - void testErrorResponse() throws IOException { + void testErrorResponse() { List> respClasses = List.of(RecordSingleResponse.class, RecordMultipleResponse.class, ZoneMultipleResponse.class, BatchResponse.class); respClasses.forEach(this::assertErrorResponse); @@ -46,7 +46,7 @@ public class ObjectMapperTest { assertFalse(resultInfo.isSuccess()); assertEquals(1, resultInfo.getErrors().size()); assertEquals(81053, resultInfo.getErrors().get(0).getCode()); - } catch (IOException e) { + } catch (JacksonException e) { fail("fail for " + clazz + ": " + e.getMessage()); } }