From 02e1eebdf522cf3eaf8ec6fcc00749708dac9c0d Mon Sep 17 00:00:00 2001 From: shayaantx <5449086+shayaantx@users.noreply.github.com> Date: Sun, 27 Feb 2022 19:56:06 -0500 Subject: [PATCH] Escape unicode characters for lidarr v1/v0 (#59) --- pom.xml | 10 ++++++++++ src/main/java/com/botdarr/api/lidarr/LidarrApi.java | 10 ++++++++-- src/main/resources/version.txt | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c9e6a24..51c9794 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,16 @@ commons-io 2.7 + + com.fasterxml.jackson.core + jackson-core + 2.13.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + com.google.guava guava diff --git a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java index c9861c2..9d549ca 100644 --- a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java +++ b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java @@ -8,6 +8,8 @@ import com.botdarr.clients.ChatClientResponseBuilder; import com.botdarr.commands.CommandContext; import com.botdarr.connections.ConnectionHelper; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.*; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; @@ -270,11 +272,15 @@ private ChatClientResponse addArtist(LidarrArtist lidarrArtist) { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpPost post = new HttpPost(getApiUrl(SonarrUrls.ARTIST_BASE)); post.addHeader("content-type", "application/json"); - String json = new Gson().toJson(lidarrArtist, LidarrArtist.class); + + ObjectMapper mapper = new ObjectMapper(); + //lidarr for some reason doesn't support raw unicode characters in json parsing (since they should be allowed), so we escape them here + mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true); + String json = mapper.writeValueAsString(lidarrArtist); post.setEntity(new StringEntity(json)); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Client request=" + post.toString()); + LOGGER.debug("Client request=" + post); LOGGER.debug("Client data=" + (json)); } diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 8044406..fb467b1 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -5.2.1 \ No newline at end of file +5.2.2 \ No newline at end of file