Skip to content

Commit d907733

Browse files
Add tests
Signed-off-by: Anders Swanson <[email protected]>
1 parent 559a92c commit d907733

File tree

2 files changed

+22
-5
lines changed
  • database/starters/oracle-spring-boot-starter-json-collections/src

2 files changed

+22
-5
lines changed

database/starters/oracle-spring-boot-starter-json-collections/src/main/java/com/oracle/spring/json/jsonb/JSONB.java

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
package com.oracle.spring.json.jsonb;
44

5+
import java.io.ByteArrayInputStream;
56
import java.io.ByteArrayOutputStream;
67
import java.io.IOException;
78
import java.io.InputStream;
@@ -43,6 +44,12 @@ public JsonParser toJsonParser(Object o) {
4344
return oracleJsonFactory.createJsonBinaryParser(buf).wrap(JsonParser.class);
4445
}
4546

47+
public <T> T fromOSON(byte[] oson, Class<T> clazz) throws IOException {
48+
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(oson)) {
49+
return fromOSON(inputStream, clazz);
50+
}
51+
}
52+
4653
public <T> T fromOSON(JsonParser parser, Class<T> clazz) {
4754
return jsonb.fromJson(parser, clazz);
4855
}

database/starters/oracle-spring-boot-starter-json-collections/src/test/java/com/oracle/spring/json/jsonb/JSONBTest.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.oracle.spring.json.jsonb;
44

55
import java.io.ByteArrayInputStream;
6+
import java.io.IOException;
67
import java.io.InputStream;
78
import java.nio.ByteBuffer;
89

@@ -36,8 +37,7 @@ void toOSON() {
3637
void parserToObject() {
3738
JsonParser parser = jsonb.toJsonParser(s);
3839
Student student = jsonb.fromOSON(parser, Student.class);
39-
assertThat(student).isNotNull();
40-
assertThat(student).isEqualTo(s);
40+
validateStudent(student);
4141
}
4242

4343
@Test
@@ -46,16 +46,26 @@ void inputStreamToObject() {
4646
InputStream is = new ByteArrayInputStream(oson);
4747

4848
Student student = jsonb.fromOSON(is, Student.class);
49-
assertThat(student).isNotNull();
50-
assertThat(student).isEqualTo(s);
49+
validateStudent(student);
5150
}
5251

5352
@Test
54-
void byteBufferToOjbect() {
53+
void byteBufferToObject() {
5554
byte[] oson = jsonb.toOSON(s);
5655
ByteBuffer buf = ByteBuffer.wrap(oson);
5756

5857
Student student = jsonb.fromOSON(buf, Student.class);
58+
validateStudent(student);
59+
}
60+
61+
@Test
62+
void byteArrayToObject() throws IOException {
63+
byte[] oson = jsonb.toOSON(s);
64+
Student student = jsonb.fromOSON(oson, Student.class);
65+
validateStudent(student);
66+
}
67+
68+
void validateStudent(Student student) {
5969
assertThat(student).isNotNull();
6070
assertThat(student).isEqualTo(s);
6171
}

0 commit comments

Comments
 (0)