Skip to content

Commit 24e9d7b

Browse files
JSON Collections Starter documentation (#166)
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent d92a850 commit 24e9d7b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spring-cloud-oci/docs/src/main/asciidoc/db_starters.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,57 @@ dependencies {
246246
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-wallet:24.4.0'
247247
}
248248
----
249+
250+
=== Oracle JSON Collections
251+
252+
This starter provides dependencies and tooling for using JSON with Oracle Database, including Oracle Database JSON Relational Duality Views.
253+
254+
[source,xml]
255+
----
256+
<dependency>
257+
<groupId>com.oracle.database.spring</groupId>
258+
<artifactId>oracle-spring-boot-starter-json-collections</artifactId>
259+
<version>24.4.0</version>
260+
</dependency>
261+
----
262+
263+
For Gradle projects, add this dependency:
264+
265+
[source,subs="normal"]
266+
----
267+
dependencies {
268+
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-json-collections:24.4.0'
269+
}
270+
----
271+
272+
==== Using the Oracle JSON Collections Starter
273+
274+
The `JSONB` bean is used to convert Java Obects to and from OSON (Oracle Database serialized JSON), using the `fromOSON` and `toOSON` methods.
275+
276+
[source,java]
277+
----
278+
@Autowired
279+
JSONB jsonb;
280+
281+
// Convert from OSON to Java Object
282+
Student student = jsonb.fromOSON(inputStream, Student.class);
283+
// Convert from Java Object to OSON
284+
byte[] bytes = jsonb.toOSON(student);
285+
----
286+
287+
The `JSONBRowMapper` implementation converts OSON database columns to Java Objects:
288+
289+
[source,java]
290+
----
291+
RowMapper<Student> rowMapper = new JSONBRowMapper<>(this.jsonb, Student.class);
292+
List<Student> students = jdbcTemplate.query(con -> {
293+
PreparedStatement ps = con.prepareStatement("""
294+
select * from students_dv v
295+
where v.data.first_name = ?
296+
and v.data.last_name = ?
297+
""");
298+
ps.setString(1, firstName);
299+
ps.setString(2, lastName);
300+
return ps;
301+
}, rowMapper);
302+
----

0 commit comments

Comments
 (0)