Skip to content

JSON Collections Starter documentation #166

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 1 commit into from
Jan 13, 2025
Merged
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
54 changes: 54 additions & 0 deletions spring-cloud-oci/docs/src/main/asciidoc/db_starters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,57 @@ dependencies {
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-wallet:24.4.0'
}
----

=== Oracle JSON Collections

This starter provides dependencies and tooling for using JSON with Oracle Database, including Oracle Database JSON Relational Duality Views.

[source,xml]
----
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-json-collections</artifactId>
<version>24.4.0</version>
</dependency>
----

For Gradle projects, add this dependency:

[source,subs="normal"]
----
dependencies {
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-json-collections:24.4.0'
}
----

==== Using the Oracle JSON Collections Starter

The `JSONB` bean is used to convert Java Obects to and from OSON (Oracle Database serialized JSON), using the `fromOSON` and `toOSON` methods.

[source,java]
----
@Autowired
JSONB jsonb;

// Convert from OSON to Java Object
Student student = jsonb.fromOSON(inputStream, Student.class);
// Convert from Java Object to OSON
byte[] bytes = jsonb.toOSON(student);
----

The `JSONBRowMapper` implementation converts OSON database columns to Java Objects:

[source,java]
----
RowMapper<Student> rowMapper = new JSONBRowMapper<>(this.jsonb, Student.class);
List<Student> students = jdbcTemplate.query(con -> {
PreparedStatement ps = con.prepareStatement("""
select * from students_dv v
where v.data.first_name = ?
and v.data.last_name = ?
""");
ps.setString(1, firstName);
ps.setString(2, lastName);
return ps;
}, rowMapper);
----
Loading