Skip to content

Commit

Permalink
Escape unicode characters for lidarr v1/v0 (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx authored Feb 28, 2022
1 parent 8f40d62 commit 02e1eeb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/botdarr/api/lidarr/LidarrApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.1
5.2.2

0 comments on commit 02e1eeb

Please sign in to comment.