diff --git a/build.gradle b/build.gradle index 7e140f6..f54daf9 100644 --- a/build.gradle +++ b/build.gradle @@ -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) } } } diff --git a/gradle.properties.example b/gradle.properties.example index 62d8d5c..31e2e9a 100644 --- a/gradle.properties.example +++ b/gradle.properties.example @@ -1,2 +1,2 @@ giteaUser= -giteaPassword= \ No newline at end of file +giteaToken= \ No newline at end of file diff --git a/src/main/java/de/catmangames/jsonfetcher/JsonFetcher.java b/src/main/java/de/catmangames/jsonfetcher/JsonFetcher.java index 6882ea1..16fff59 100644 --- a/src/main/java/de/catmangames/jsonfetcher/JsonFetcher.java +++ b/src/main/java/de/catmangames/jsonfetcher/JsonFetcher.java @@ -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 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 fetch(String path, Class type) throws IOException { - return mapper.readValue(getRaw(path), type); + return gson.fromJson(getRaw(path), type); } - public T fetch(String path, TypeReference type) throws IOException { - return mapper.readValue(getRaw(path), type); + public T fetch(String path, TypeToken type) throws IOException { + return gson.fromJson(getRaw(path), type.getType()); } private String getRaw(String path) throws IOException {