Skip to content

Commit dae666a

Browse files
JSON Starter Javadoc
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent b2e6adc commit dae666a

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

database/starters/oracle-spring-boot-json-data-tools/src/main/java/com/oracle/spring/json/JsonCollectionsAutoConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1414
import org.springframework.context.annotation.Bean;
1515

16+
/**
17+
* Autoconfiguration for the JSON Collections beans.
18+
* OKafka-related beans are only instantiated if the required interfaces
19+
* are on the classpath.
20+
*/
1621
@AutoConfiguration
1722
public class JsonCollectionsAutoConfiguration {
1823
@Bean

database/starters/oracle-spring-boot-json-data-tools/src/main/java/com/oracle/spring/json/jsonb/JSONB.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414
import oracle.sql.json.OracleJsonFactory;
1515
import org.eclipse.yasson.YassonJsonb;
1616

17+
/**
18+
* The JSONB bean provides utility methods to convert Java objects to and from OSON.
19+
* You may inject this bean into your application, or use the createDefault factory
20+
* method to create a new instance.
21+
*/
1722
public class JSONB {
1823
private final OracleJsonFactory oracleJsonFactory;
1924
private final YassonJsonb jsonb;
2025

26+
/**
27+
* Create a new JSONB instance.
28+
* @return Default JSONB instance.
29+
*/
2130
public static JSONB createDefault() {
2231
return new JSONB(new OracleJsonFactory(), (YassonJsonb) JsonbBuilder.create());
2332
}
@@ -27,6 +36,11 @@ public JSONB(OracleJsonFactory oracleJsonFactory, YassonJsonb jsonb) {
2736
this.jsonb = jsonb;
2837
}
2938

39+
/**
40+
* Converts a Java object to an OSON byte array.
41+
* @param o Java object to convert to OSON.
42+
* @return OSON byte array.
43+
*/
3044
public byte[] toOSON(Object o) {
3145
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
3246
JsonGenerator gen = oracleJsonFactory.createJsonBinaryGenerator(outputStream).wrap(JsonGenerator.class);
@@ -38,27 +52,60 @@ public byte[] toOSON(Object o) {
3852
}
3953
}
4054

55+
/**
56+
* Creates an OSON JsonParser from a Java object.
57+
* @param o Java object to create a JsonParser from.
58+
* @return JsonParser for generating OSON.
59+
*/
4160
public JsonParser toJsonParser(Object o) {
4261
byte[] oson = toOSON(o);
4362
ByteBuffer buf = ByteBuffer.wrap(oson);
4463
return oracleJsonFactory.createJsonBinaryParser(buf).wrap(JsonParser.class);
4564
}
4665

66+
/**
67+
* Convert an OSON byte array to a Java object of type T.
68+
* @param oson OSON byte array.
69+
* @param clazz Java class to convert OSON to.
70+
* @param <T> Type parameter for the Java conversion class.
71+
* @return Converted Java object of type T.
72+
* @throws IOException When OSON parsing fails.
73+
*/
4774
public <T> T fromOSON(byte[] oson, Class<T> clazz) throws IOException {
4875
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(oson)) {
4976
return fromOSON(inputStream, clazz);
5077
}
5178
}
5279

80+
/**
81+
* Create a Java object of type T from an OSON JsonParser.
82+
* @param parser OSON JsonParser.
83+
* @param clazz Java object to create.
84+
* @param <T> Type parameter for the Java object.
85+
* @return Converted Java object of type T.
86+
*/
5387
public <T> T fromOSON(JsonParser parser, Class<T> clazz) {
5488
return jsonb.fromJson(parser, clazz);
5589
}
5690

91+
/**
92+
* Create a Java object from an OSON InputStream.
93+
* @param inputStream OSON InputStream.
94+
* @param clazz Java object to create.
95+
* @param <T> Type parameter for the Java object.
96+
* @return Converted Java object of type T.
97+
*/
5798
public <T> T fromOSON(InputStream inputStream, Class<T> clazz) {
5899
JsonParser jsonParser = oracleJsonFactory.createJsonBinaryParser(inputStream).wrap(JsonParser.class);
59100
return jsonb.fromJson(jsonParser, clazz);
60101
}
61102

103+
/** Create a Java Object from an OSON ByteBuffer.
104+
* @param byteBuffer OSON ByteBuffer.
105+
* @param clazz Java object to create.
106+
* @param <T> Type parameter for the Java object.
107+
* @return Converted Java object of type T.
108+
*/
62109
public <T> T fromOSON(ByteBuffer byteBuffer, Class<T> clazz) {
63110
JsonParser jsonParser = oracleJsonFactory.createJsonBinaryParser(byteBuffer).wrap(JsonParser.class);
64111
return jsonb.fromJson(jsonParser, clazz);

database/starters/oracle-spring-boot-json-data-tools/src/main/java/com/oracle/spring/json/jsonb/JSONBRowMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import jakarta.json.stream.JsonParser;
99
import org.springframework.jdbc.core.RowMapper;
1010

11+
/**
12+
* JSONBRowMapper maps Oracle Database JSON row data to Java objects.
13+
* @param <T> Type parameter to convert JSON row data into.
14+
*/
1115
public class JSONBRowMapper<T> implements RowMapper<T> {
1216
private final JSONB mapper;
1317
private final Class<T> clazz;

database/starters/oracle-spring-boot-json-data-tools/src/main/java/com/oracle/spring/json/kafka/OSONKafkaSerializationFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import com.oracle.spring.json.jsonb.JSONB;
66

7+
/**
8+
* Factory class to create OSONDeserializer and OSONSerializer instances.
9+
*/
710
public class OSONKafkaSerializationFactory {
811
private final JSONB jsonb;
912

0 commit comments

Comments
 (0)