diff --git a/ezyhttp-client/pom.xml b/ezyhttp-client/pom.xml index d2b22fd..c8036d7 100644 --- a/ezyhttp-client/pom.xml +++ b/ezyhttp-client/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-client diff --git a/ezyhttp-core/pom.xml b/ezyhttp-core/pom.xml index 716fc74..eb80e02 100644 --- a/ezyhttp-core/pom.xml +++ b/ezyhttp-core/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-core diff --git a/ezyhttp-core/src/main/java/com/tvd12/ezyhttp/core/codec/JsonBodyConverter.java b/ezyhttp-core/src/main/java/com/tvd12/ezyhttp/core/codec/JsonBodyConverter.java index dd0857c..94a711b 100644 --- a/ezyhttp-core/src/main/java/com/tvd12/ezyhttp/core/codec/JsonBodyConverter.java +++ b/ezyhttp-core/src/main/java/com/tvd12/ezyhttp/core/codec/JsonBodyConverter.java @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets; import com.fasterxml.jackson.databind.ObjectMapper; +import com.tvd12.ezyfox.stream.EzyInputStreams; import com.tvd12.ezyhttp.core.data.BodyData; public class JsonBodyConverter implements BodyConverter { @@ -33,8 +34,11 @@ public T deserialize(BodyData data, Class bodyType) throws IOException { return deserialize(inputStream, bodyType); } + @SuppressWarnings("unchecked") @Override public T deserialize(InputStream inputStream, Class bodyType) throws IOException { - return objectMapper.readValue(inputStream, bodyType); + return bodyType == String.class + ? (T) EzyInputStreams.toStringUtf8(inputStream) + : objectMapper.readValue(inputStream, bodyType); } } diff --git a/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/codec/JsonBodyConverterTest.java b/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/codec/JsonBodyConverterTest.java index 6637295..39ce479 100644 --- a/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/codec/JsonBodyConverterTest.java +++ b/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/codec/JsonBodyConverterTest.java @@ -117,6 +117,23 @@ public void deserializeFromBodyData() throws Exception { verify(bodyData, times(1)).getInputStream(); } + @Test + public void deserializeStringToStringTest() throws Exception { + // given + JsonBodyConverter sut = new JsonBodyConverter(new ObjectMapper()); + + String body = "{\"hello\":\"world\",\"foo\":\"bar\"}"; + + // when + String actual = sut.deserialize( + new ByteArrayInputStream(body.getBytes()), + String.class + ); + + // then + Asserts.assertEquals(body, actual); + } + @Data @AllArgsConstructor diff --git a/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/io/BytesRangeFileInputStreamTest.java b/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/io/BytesRangeFileInputStreamTest.java index 3999542..fcc989f 100644 --- a/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/io/BytesRangeFileInputStreamTest.java +++ b/ezyhttp-core/src/test/java/com/tvd12/ezyhttp/core/test/io/BytesRangeFileInputStreamTest.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.RandomAccessFile; import java.nio.file.Files; @@ -311,4 +312,23 @@ public void seekErrorTest() { // then Asserts.assertEqualsType(e, IllegalArgumentException.class); } + + @Test + public void seekIoErrorTest() { + // given + final String pomFilePath = "pom.xml"; + final String range = "bytes=-1-2"; + + // when + final Throwable e = Asserts.assertThrows( + () -> new BytesRangeFileInputStream( + pomFilePath, + -1, + -2 + ) + ); + + // then + Asserts.assertEqualsType(e, IOException.class); + } } diff --git a/ezyhttp-server-boot/pom.xml b/ezyhttp-server-boot/pom.xml index e0e72d7..e55dddc 100644 --- a/ezyhttp-server-boot/pom.xml +++ b/ezyhttp-server-boot/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-boot diff --git a/ezyhttp-server-core/pom.xml b/ezyhttp-server-core/pom.xml index 5867edc..dbe2f12 100644 --- a/ezyhttp-server-core/pom.xml +++ b/ezyhttp-server-core/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-core diff --git a/ezyhttp-server-graphql/pom.xml b/ezyhttp-server-graphql/pom.xml index 80cfae7..b56065d 100644 --- a/ezyhttp-server-graphql/pom.xml +++ b/ezyhttp-server-graphql/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-graphql diff --git a/ezyhttp-server-jetty/pom.xml b/ezyhttp-server-jetty/pom.xml index ae9119d..bf1f7af 100644 --- a/ezyhttp-server-jetty/pom.xml +++ b/ezyhttp-server-jetty/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-jetty diff --git a/ezyhttp-server-management/pom.xml b/ezyhttp-server-management/pom.xml index f675f3f..8ec4a2c 100644 --- a/ezyhttp-server-management/pom.xml +++ b/ezyhttp-server-management/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-management ezyhttp-server-management diff --git a/ezyhttp-server-thymeleaf/pom.xml b/ezyhttp-server-thymeleaf/pom.xml index 6b49797..9c699ef 100644 --- a/ezyhttp-server-thymeleaf/pom.xml +++ b/ezyhttp-server-thymeleaf/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-thymeleaf diff --git a/ezyhttp-server-tomcat/pom.xml b/ezyhttp-server-tomcat/pom.xml index 465de81..b0ff0ea 100644 --- a/ezyhttp-server-tomcat/pom.xml +++ b/ezyhttp-server-tomcat/pom.xml @@ -5,7 +5,7 @@ com.tvd12 ezyhttp - 1.2.8 + 1.2.9 ezyhttp-server-tomcat diff --git a/pom.xml b/pom.xml index 5505198..d5cb6a1 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 1.0.6 ezyhttp - 1.2.8 + 1.2.9 pom ezyhttp