Migrate from Jackson to Gson for JSON handling and update build configuration for token-based authentication.

This commit is contained in:
2026-04-23 05:53:15 +02:00
parent 00b3dbda8c
commit cfab96b15e
3 changed files with 18 additions and 13 deletions
+10 -5
View File
@@ -16,7 +16,7 @@ repositories {
}
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
implementation 'com.google.code.gson:gson:2.10.1'
}
publishing {
@@ -28,10 +28,15 @@ publishing {
repositories {
maven {
name = 'gitea'
url = 'https://git.catlet.de/api/packages/DEIN_USER/maven'
credentials {
username = findProperty('giteaUser')
password = findProperty('giteaPassword')
url = 'https://git.catlet.info/api/packages/StateMc/maven'
credentials(HttpHeaderCredentials) {
name = 'Authorization'
value = 'Basic ' + Base64.encoder.encodeToString(
"${findProperty('giteaUser')}:${findProperty('giteaToken')}".bytes
)
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
+1 -1
View File
@@ -1,2 +1,2 @@
giteaUser=
giteaPassword=
giteaToken=
@@ -1,7 +1,7 @@
package de.catmangames.jsonfetcher;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.net.http.HttpClient;
@@ -13,9 +13,10 @@ import java.util.concurrent.ConcurrentHashMap;
public class JsonFetcher {
private final Gson gson = new Gson();
private final String baseUrl;
private final HttpClient client;
private final ObjectMapper mapper;
private final long cacheTtlMs;
private final Map<String, long[]> cacheTimestamps = new ConcurrentHashMap<>();
@@ -26,16 +27,15 @@ public class JsonFetcher {
this.client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(b.timeoutSec))
.build();
this.mapper = new ObjectMapper();
this.cacheTtlMs = b.cacheTtlMs;
}
public <T> T fetch(String path, Class<T> type) throws IOException {
return mapper.readValue(getRaw(path), type);
return gson.fromJson(getRaw(path), type);
}
public <T> T fetch(String path, TypeReference<T> type) throws IOException {
return mapper.readValue(getRaw(path), type);
public <T> T fetch(String path, TypeToken<T> type) throws IOException {
return gson.fromJson(getRaw(path), type.getType());
}
private String getRaw(String path) throws IOException {