Skip to content
Permalink
Browse files
IGNITE-16567 Remove GSON dependency (#669)
  • Loading branch information
sashapolo committed Feb 17, 2022
1 parent 817995d commit 66108f5e594cfb82f2157a460f55207740d43b20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
@@ -64,11 +64,6 @@
</dependency>

<!-- 3rd party dependencies -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
@@ -50,8 +50,8 @@

<!-- 3rd party dependencies -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
@@ -17,19 +17,24 @@

package org.apache.ignite.internal.rest.netty;

import com.google.gson.Gson;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import java.nio.charset.StandardCharsets;

/**
* Simple wrapper of HTTP response with some helper methods for filling it with headers and content.
*/
public class RestApiHttpResponse {
private static final ObjectMapper objectMapper = new ObjectMapper()
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

/** Response. */
private final HttpResponse res;

@@ -83,9 +88,14 @@ public byte[] content() {
* @return Updated response.
*/
public RestApiHttpResponse json(Object content) {
// TODO: IGNITE-14344 Gson object should not be created on every response
this.content = new Gson().toJson(content).getBytes(StandardCharsets.UTF_8);
try {
this.content = objectMapper.writeValueAsBytes(content);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Unable to serialize JSON content", e);
}

headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());

return this;
}

@@ -52,8 +52,7 @@
<apache.ivy.version>2.5.0</apache.ivy.version>
<asm.framework.version>9.0</asm.framework.version>
<compile.testing.library.version>0.19</compile.testing.library.version>
<gson.version>2.8.6</gson.version>
<jackson.version>2.12.3</jackson.version>
<jackson.version>2.13.1</jackson.version>
<jansi.version>1.18</jansi.version>
<netty.version>4.1.70.Final</netty.version>
<javapoet.version>1.13.0</javapoet.version>
@@ -323,21 +322,11 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
@@ -448,12 +437,6 @@
<version>${javapoet.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>

<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>

0 comments on commit 66108f5

Please sign in to comment.