Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11
25
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 4.7.0
* Bump Jackson module to Jackson 3. This also requires the Jackson module to be at Java 17. All other modules are still at 11
* Users who wish to continue to use Jackson 2 may still pull in the last Jackson module on that version (4.6.1). It will continue to be compatible with Unirest 4

## 4.6.1
* Minor dependency bumps

## 4.6.0
* Add support for multiple proxies and authentication per host

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.konghq</groupId>
<artifactId>unirest-java-parent</artifactId>
<packaging>pom</packaging>
<version>4.6.1-SNAPSHOT</version>
<version>4.7.0-SNAPSHOT</version>
<name>unirest</name>
<description>Parent pom for unirest packages</description>
<url>http://github.com/Kong/unirest-java/</url>
Expand All @@ -30,7 +30,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jackson.version>2.20.1</jackson.version>
<jackson.version>3.0.2</jackson.version>
<main.dir>${project.basedir}</main.dir>
<junit.version>5.14.1</junit.version>
<mockito.version>5.20.0</mockito.version>
Expand Down Expand Up @@ -385,4 +385,4 @@
</plugins>
</reporting>

</project>
</project>
8 changes: 4 additions & 4 deletions unirest-bdd-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>unirest-java-parent</artifactId>
<groupId>com.konghq</groupId>
<version>4.6.1-SNAPSHOT</version>
<version>4.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -36,13 +36,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<groupId>tools.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
Expand All @@ -55,4 +55,4 @@
</dependency>
</dependencies>

</project>
</project>
16 changes: 8 additions & 8 deletions unirest-bdd-tests/src/test/java/BehaviorTests/AsObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

package BehaviorTests;

import com.fasterxml.jackson.databind.DeserializationFeature;
import tools.jackson.databind.DeserializationFeature;
import com.google.gson.Gson;
import kong.unirest.core.*;
import kong.unirest.modules.gson.GsonObjectMapper;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.json.JsonMapper;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand Down Expand Up @@ -160,7 +161,7 @@ void ifTheObjectMapperFailsReturnEmptyAndAddToParsingError() {
assertNull(request.getBody());
assertTrue(request.getParsingError().isPresent());
assertThat(request.getParsingError().get().getMessage())
.startsWith("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: " +
.startsWith("kong.unirest.core.UnirestException: tools.jackson.core.exc.StreamReadException: " +
"Unrecognized token 'You': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')");
assertEquals("You did something bad", request.getParsingError().get().getOriginalBody());

Expand All @@ -174,7 +175,7 @@ void ifTheObjectMapperFailsReturnEmptyAndAddToParsingErrorObGenericTypes() {
assertNull(request.getBody());
assertTrue(request.getParsingError().isPresent());
assertThat(request.getParsingError().get().getMessage())
.startsWith("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: " +
.startsWith("kong.unirest.core.UnirestException: tools.jackson.core.exc.StreamReadException: " +
"Unrecognized token 'You': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')");
assertEquals("You did something bad", request.getParsingError().get().getOriginalBody());
}
Expand All @@ -187,15 +188,14 @@ void unirestExceptionsAreAlsoParseExceptions() {
assertNull(request.getBody());
assertTrue(request.getParsingError().isPresent());
assertThat(request.getParsingError().get().getMessage())
.startsWith("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: " +
.startsWith("kong.unirest.core.UnirestException: tools.jackson.core.exc.StreamReadException: " +
"Unrecognized token 'You': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')");
assertEquals("You did something bad", request.getParsingError().get().getOriginalBody());
}

@Test
void canSetObjectMapperToFailOnUnknown() {
var jack = new com.fasterxml.jackson.databind.ObjectMapper();
jack.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
var jack = JsonMapper.builderWithJackson2Defaults().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true).build();

Unirest.config().setObjectMapper(new JacksonObjectMapper(jack));

Expand Down Expand Up @@ -231,8 +231,8 @@ void parsingExceptions() {
private static void assertParsingError(UnirestParsingException e) {
assertThat(e)
.isInstanceOf(UnirestParsingException.class)
.hasMessage("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'hi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" +
" at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 3]");
.hasMessage("kong.unirest.core.UnirestException: tools.jackson.core.exc.StreamReadException: Unrecognized token 'hi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" +
" at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #UNKNOWN]");
}

static class SomeTestClass {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
package BehaviorTests;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import kong.unirest.core.HttpResponse;
import kong.unirest.core.Unirest;
import org.junit.jupiter.api.Test;
import tools.jackson.core.StreamWriteFeature;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -39,7 +37,7 @@ class ErrorParsingTest extends BddTest {
private boolean errorCalled;

@Test
void passParsingErrorsOnInFalure() {
void passParsingErrorsOnInFailure() {
MockServer.setStringResponse("not json");

Unirest.get(MockServer.GET)
Expand Down Expand Up @@ -110,8 +108,10 @@ void ifNoErrorThenGetTheRegularBody() {
@Test
void failsIfErrorResponseCantBeMapped() {
var om = new JacksonObjectMapper();
om.om.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, false);
om.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
om.om = om.om.rebuild()
.configure(StreamWriteFeature.IGNORE_UNKNOWN, false)
.configure(tools.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.build();

MockServer.setJsonAsResponse(new ErrorThing("boom!"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,48 @@

package BehaviorTests;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.core.JsonParser;
import tools.jackson.core.StreamWriteFeature;
import tools.jackson.databind.*;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.databind.module.SimpleModule;
import tools.jackson.datatype.guava.GuavaModule;
import kong.unirest.core.*;
import kong.unirest.core.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class JacksonObjectMapper implements kong.unirest.core.ObjectMapper {

public final com.fasterxml.jackson.databind.ObjectMapper om;
public tools.jackson.databind.ObjectMapper om;

public JacksonObjectMapper(com.fasterxml.jackson.databind.ObjectMapper om){
public JacksonObjectMapper(tools.jackson.databind.ObjectMapper om){
this.om = om;
}

public JacksonObjectMapper(){
this(new com.fasterxml.jackson.databind.ObjectMapper());
om.registerModule(new GuavaModule());
JsonMapper.Builder builder = JsonMapper.builderWithJackson2Defaults();
builder.addModule(new GuavaModule());
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(JsonPatchItem.class, new PatchSerializer());
simpleModule.addSerializer(JsonPatch.class, new JsonPatchSerializer());
simpleModule.addDeserializer(JsonPatchItem.class, new PatchDeserializer());
simpleModule.addDeserializer(JsonPatch.class, new JsonPatchDeSerializer());
simpleModule.addSerializer(HttpMethod.class, new HttpMethodSerializer());
simpleModule.addDeserializer(HttpMethod.class, new HttpMethodDeSerializer());
om.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.registerModule(simpleModule);
builder.configure(StreamWriteFeature.IGNORE_UNKNOWN, true);
builder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
builder.addModule(simpleModule);
this.om = builder.build();
}

public <T> T readValue(File f, Class<T> valueType){
try {
return om.readValue(f, valueType);
} catch (IOException e) {
} catch (JacksonException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -73,7 +75,7 @@ public <T> T readValue(File f, Class<T> valueType){
public <T> T readValue(String value, Class<T> valueType) {
try {
return om.readValue(value, valueType);
} catch (IOException e) {
} catch (JacksonException e) {
throw new UnirestException(e);
}
}
Expand All @@ -82,7 +84,7 @@ public <T> T readValue(String value, Class<T> valueType) {
public <T> T readValue(String value, GenericType<T> genericType) {
try {
return om.readValue(value, om.constructType(genericType.getType()));
} catch (IOException e) {
} catch (JacksonException e) {
throw new UnirestException(e);
}
}
Expand All @@ -91,67 +93,67 @@ public <T> T readValue(String value, GenericType<T> genericType) {
public String writeValue(Object value) {
try {
return om.writeValueAsString(value);
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
throw new UnirestException(e);
}
}

public <T> T readValue(InputStream rawBody, Class<T> as) {
try {
return om.readValue(rawBody, as);
} catch (IOException e) {
} catch (JacksonException e) {
throw new RuntimeException(e);
}
}

public <T> T readValue(byte[] content, Class<T> clazz) {
try {
return om.readValue(content, clazz);
} catch (IOException e) {
} catch (JacksonException e) {
throw new RuntimeException(e);
}
}

public static class JsonPatchSerializer extends JsonSerializer<JsonPatch>{
@Override
public void serialize(JsonPatch patch, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException {
jgen.writeRawValue(patch.toString());
}
}
public static class JsonPatchSerializer extends ValueSerializer<JsonPatch>{
@Override
public void serialize(JsonPatch patch, JsonGenerator jgen, SerializationContext ctxt) throws JacksonException {
jgen.writeRawValue(patch.toString());
}
}

public static class JsonPatchDeSerializer extends JsonDeserializer<JsonPatch>{
public static class JsonPatchDeSerializer extends ValueDeserializer<JsonPatch>{
@Override
public JsonPatch deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
public JsonPatch deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
String s = jsonParser.readValueAsTree().toString();
return new JsonPatch(s);
}
}

public static class PatchSerializer extends JsonSerializer<JsonPatchItem> {
@Override
public void serialize(JsonPatchItem jwk, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException {
jgen.writeRaw(jwk.toString());
}
}
public static class PatchSerializer extends ValueSerializer<JsonPatchItem> {
@Override
public void serialize(JsonPatchItem jwk, JsonGenerator jgen, SerializationContext ctxt) throws JacksonException {
jgen.writeRaw(jwk.toString());
}
}

public static class PatchDeserializer extends JsonDeserializer<JsonPatchItem> {
public static class PatchDeserializer extends ValueDeserializer<JsonPatchItem> {
@Override
public JsonPatchItem deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
public JsonPatchItem deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
String s = jsonParser.readValueAsTree().toString();
return new JsonPatchItem(new JSONObject(s));
}
}

public static class HttpMethodSerializer extends JsonSerializer<HttpMethod> {
@Override
public void serialize(HttpMethod httpMethod, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException {
jgen.writeString(httpMethod.name());
}
}
public static class HttpMethodSerializer extends ValueSerializer<HttpMethod> {
@Override
public void serialize(HttpMethod httpMethod, JsonGenerator jgen, SerializationContext ctxt) throws JacksonException {
jgen.writeString(httpMethod.name());
}
}

public static class HttpMethodDeSerializer extends JsonDeserializer<HttpMethod> {
public static class HttpMethodDeSerializer extends ValueDeserializer<HttpMethod> {
@Override
public HttpMethod deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
public HttpMethod deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
String s = jsonParser.readValueAs(String.class);
return HttpMethod.valueOf(s);
}
Expand Down
14 changes: 6 additions & 8 deletions unirest-bdd-tests/src/test/java/BehaviorTests/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

package BehaviorTests;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.datatype.guava.GuavaModule;
import com.google.common.base.Charsets;
import com.google.common.collect.Multimap;
import com.google.common.io.Resources;
Expand All @@ -53,16 +55,12 @@
import static org.mockito.Mockito.when;

class TestUtil {
private static final ObjectMapper om = new ObjectMapper();

static {
om.registerModule(new GuavaModule());
}
private static final ObjectMapper om = JsonMapper.builderWithJackson2Defaults().addModule(new GuavaModule()).build();

public static <T> T readValue(String body, Class<T> as) {
try {
return om.readValue(body, as);
} catch (IOException e) {
} catch (JacksonException e) {
throw new RuntimeException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion unirest-java-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>unirest-java-parent</artifactId>
<groupId>com.konghq</groupId>
<version>4.6.1-SNAPSHOT</version>
<version>4.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>unirest-java-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion unirest-modules-gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.konghq</groupId>
<artifactId>unirest-java-parent</artifactId>
<version>4.6.1-SNAPSHOT</version>
<version>4.7.0-SNAPSHOT</version>
</parent>

<artifactId>unirest-modules-gson</artifactId>
Expand Down
Loading
Loading