Skip to content

Commit

Permalink
version 1.2.9: update JsonBodyConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 committed Mar 30, 2024
1 parent acf6f1e commit 734f173
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ezyhttp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -33,8 +34,11 @@ public <T> T deserialize(BodyData data, Class<T> bodyType) throws IOException {
return deserialize(inputStream, bodyType);
}

@SuppressWarnings("unchecked")
@Override
public <T> T deserialize(InputStream inputStream, Class<T> bodyType) throws IOException {
return objectMapper.readValue(inputStream, bodyType);
return bodyType == String.class
? (T) EzyInputStreams.toStringUtf8(inputStream)
: objectMapper.readValue(inputStream, bodyType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion ezyhttp-server-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-server-boot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-server-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-graphql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>
<artifactId>ezyhttp-server-graphql</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-server-jetty</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>
<artifactId>ezyhttp-server-management</artifactId>
<name>ezyhttp-server-management</name>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-thymeleaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>
<artifactId>ezyhttp-server-thymeleaf</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-tomcat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
</parent>

<artifactId>ezyhttp-server-tomcat</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.0.6</version>
</parent>
<artifactId>ezyhttp</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
<packaging>pom</packaging>

<name>ezyhttp</name>
Expand Down

0 comments on commit 734f173

Please sign in to comment.