Skip to content

JSON Starter Javadoc #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;

/**
* Autoconfiguration for the JSON Collections beans.
* OKafka-related beans are only instantiated if the required interfaces
* are on the classpath.
*/
@AutoConfiguration
public class JsonCollectionsAutoConfiguration {
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
import oracle.sql.json.OracleJsonFactory;
import org.eclipse.yasson.YassonJsonb;

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

/**
* Create a new JSONB instance.
* @return Default JSONB instance.
*/
public static JSONB createDefault() {
return new JSONB(new OracleJsonFactory(), (YassonJsonb) JsonbBuilder.create());
}
Expand All @@ -27,6 +36,11 @@ public JSONB(OracleJsonFactory oracleJsonFactory, YassonJsonb jsonb) {
this.jsonb = jsonb;
}

/**
* Converts a Java object to an OSON byte array.
* @param o Java object to convert to OSON.
* @return OSON byte array.
*/
public byte[] toOSON(Object o) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
JsonGenerator gen = oracleJsonFactory.createJsonBinaryGenerator(outputStream).wrap(JsonGenerator.class);
Expand All @@ -38,27 +52,60 @@ public byte[] toOSON(Object o) {
}
}

/**
* Creates an OSON JsonParser from a Java object.
* @param o Java object to create a JsonParser from.
* @return JsonParser for generating OSON.
*/
public JsonParser toJsonParser(Object o) {
byte[] oson = toOSON(o);
ByteBuffer buf = ByteBuffer.wrap(oson);
return oracleJsonFactory.createJsonBinaryParser(buf).wrap(JsonParser.class);
}

/**
* Convert an OSON byte array to a Java object of type T.
* @param oson OSON byte array.
* @param clazz Java class to convert OSON to.
* @param <T> Type parameter for the Java conversion class.
* @return Converted Java object of type T.
* @throws IOException When OSON parsing fails.
*/
public <T> T fromOSON(byte[] oson, Class<T> clazz) throws IOException {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(oson)) {
return fromOSON(inputStream, clazz);
}
}

/**
* Create a Java object of type T from an OSON JsonParser.
* @param parser OSON JsonParser.
* @param clazz Java object to create.
* @param <T> Type parameter for the Java object.
* @return Converted Java object of type T.
*/
public <T> T fromOSON(JsonParser parser, Class<T> clazz) {
return jsonb.fromJson(parser, clazz);
}

/**
* Create a Java object from an OSON InputStream.
* @param inputStream OSON InputStream.
* @param clazz Java object to create.
* @param <T> Type parameter for the Java object.
* @return Converted Java object of type T.
*/
public <T> T fromOSON(InputStream inputStream, Class<T> clazz) {
JsonParser jsonParser = oracleJsonFactory.createJsonBinaryParser(inputStream).wrap(JsonParser.class);
return jsonb.fromJson(jsonParser, clazz);
}

/** Create a Java Object from an OSON ByteBuffer.
* @param byteBuffer OSON ByteBuffer.
* @param clazz Java object to create.
* @param <T> Type parameter for the Java object.
* @return Converted Java object of type T.
*/
public <T> T fromOSON(ByteBuffer byteBuffer, Class<T> clazz) {
JsonParser jsonParser = oracleJsonFactory.createJsonBinaryParser(byteBuffer).wrap(JsonParser.class);
return jsonb.fromJson(jsonParser, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import jakarta.json.stream.JsonParser;
import org.springframework.jdbc.core.RowMapper;

/**
* JSONBRowMapper maps Oracle Database JSON row data to Java objects.
* @param <T> Type parameter to convert JSON row data into.
*/
public class JSONBRowMapper<T> implements RowMapper<T> {
private final JSONB mapper;
private final Class<T> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

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

/**
* Factory class to create OSONDeserializer and OSONSerializer instances.
*/
public class OSONKafkaSerializationFactory {
private final JSONB jsonb;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ To use Oracle Spring Boot Starter for TxEventQ and JMS for your Spring Boot appl
or if you are using Gradle:

```text
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-aqjms:24.4.0'
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-aqjms:25.3.0'
```
2 changes: 1 addition & 1 deletion spring-cloud-oci/docs/src/main/asciidoc/aqjms.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To add this starter to your project, add this Maven dependency:
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-aqjms</artifactId>
<version>25.1.0</version>
<version>25.3.0</version>
</dependency>
----

Expand Down
4 changes: 2 additions & 2 deletions spring-cloud-oci/docs/src/main/asciidoc/jsoncollection.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This starter provides dependencies and tooling for using JSON with Oracle Databa
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-json-collections</artifactId>
<version>24.4.0</version>
<version>25.3.0</version>
</dependency>
----

Expand All @@ -20,7 +20,7 @@ For Gradle projects, add this dependency:
[source,subs="normal"]
----
dependencies {
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-json-collections:24.4.0'
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-json-collections:25.3.0'
}
----

Expand Down
4 changes: 2 additions & 2 deletions spring-cloud-oci/docs/src/main/asciidoc/ucp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To add this starter to your project, add this Maven dependency:
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
<version>24.4.0</version>
<version>25.3.0</version>
</dependency>
----

Expand All @@ -22,7 +22,7 @@ For Gradle projects, add this dependency:
[source,subs="normal"]
----
dependencies {
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-ucp:24.4.0'
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-ucp:25.3.0'
}
----

Expand Down
4 changes: 2 additions & 2 deletions spring-cloud-oci/docs/src/main/asciidoc/wallet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To add this starter to your project, add this Maven dependency:
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
<version>24.4.0</version>
<version>25.3.0</version>
</dependency>
----

Expand All @@ -22,6 +22,6 @@ For Gradle projects, add this dependency:
[source,subs="normal"]
----
dependencies {
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-wallet:24.4.0'
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-wallet:25.3.0'
}
----
Loading