Skip to content
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

Ojdbc provider jackson oson #118

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 8
java-version: 11
- name: Cache Maven packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -88,6 +88,12 @@ jobs:
OCI_PASSWORD_PAYLOAD_OCID_MULTIPLE_KEYS=${{ secrets.TEST_OCI_PASSWORD_PAYLOAD_OCID_MULTIPLE_KEYS }}\n
OCI_PASSWORD_PAYLOAD_OCID_KEY=${{ secrets.TEST_OCI_PASSWORD_PAYLOAD_OCID_KEY }}\n
" >> ojdbc-provider-oci/test.properties

# Generate ojdbc-provider-jackson-oson/test.properties
echo -e "JACKSON_OSON_URL=${{ secrets.TEST_JACKSON_OSON_URL }}\n
JACKSON_OSON_USERNAME=${{ secrets.TEST_JACKSON_OSON_USERNAME }}\n
JACKSON_OSON_PASSWORD=${{ secrets.TEST_JACKSON_OSON_PASSWORD }}\n
" >> ojdbc-provider-jackson-oson/test.properties

# Generate GCP config
echo "${{ secrets.TEST_GCP_CONFIG }}" > $HOME/.gcp/config.json
Expand All @@ -108,3 +114,5 @@ jobs:

rm $HOME/.gcp/config.json
rm ojdbc-provider-gcp/test.properties

rm ojdbc-provider-jackson-oson/test.properties
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ Implementations of service provider interfaces (SPIs) that extend the
Oracle JDBC Driver for integration with cloud services and other specialized
APIs. These SPI implementations are referred as "providers" for short.

Each module of this project contains a set of providers. Three of these modules
contain providers for a particular cloud platform:
Each module of this project contains a set of providers.

<u>Three of these modules contain providers for a particular cloud platform:</u>

<dl>
<dt><a href="ojdbc-provider-oci/README.md">Oracle JDBC OCI Providers</a></dt>
<dd>Providers for integration with Oracle Cloud Infrastructure (OCI)</dd>
<dd>Providers for integration with Oracle Cloud Infrastructure (OCI).</dd>
<dt><a href="ojdbc-provider-azure/README.md">Oracle JDBC Azure Providers</a></dt>
<dd>Providers for integration with Microsoft Azure</dd>
<dd>Providers for integration with Microsoft Azure.</dd>
<dt><a href="ojdbc-provider-gcp/README.md">Oracle JDBC GCP Providers</a></dt>
<dd>Providers for integration with Google Cloud Platform</dd>
<dd>Providers for integration with Google Cloud Platform.</dd>
</dl>
And the last one contains a provider for Open Telemetry:
<u>The next one contains a provider for Open Telemetry:</u>
<dl>
<dt><a href="ojdbc-provider-opentelemetry/README.md">Oracle JDBC Open Telemetry Provider</a></dt>
<dd>Provider for integration with Open Telemetry</dd>
<dd>Provider for integration with Open Telemetry.</dd>
</dl>
<u>And the last one contains a provider for Jackson-OSON:</u>
<dl>
<dt><a href="ojdbc-provider-jackson-oson/README.md">Oracle JDBC Jackson OSON</a></dt>
<dd>Provider for <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-in-oracle-database.html#GUID-A8A58B49-13A5-4F42-8EA0-508951DAE0BB">OSON</a> through the JACKSON APIs.
This provider can be used for seamless integration of applications that use the JACKSON APIs with the Oracle JSON type.</dd>
</dl>
Visit any of the links above to learn about providers which are available for
a particular platform.

Expand Down Expand Up @@ -126,6 +134,9 @@ this project:

[ojdbc-provider-opentelemetry](ojdbc-provider-opentelemetry/README.md#installation)

[ojdbc-provider-jackson-oson](ojdbc-provider-jackson-oson/README.md#installation)


Each module listed above is distributed on the Maven Central Repository as a
separate jar file. Coordinates can be found by visiting the links above.

Expand Down
57 changes: 57 additions & 0 deletions ojdbc-provider-jackson-oson/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# OSON Provider for Jackson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice README. It would be great if you could include a definition of the type mappings, i.e. a table with one column that lists Java types and the default OSON mapping.

Also if I want to override a mapping for some field and gain access to the underlying OracleJsonParser and OracleJsonGenerator is this possible?

## Overview
The **OSON Provider for Jackson** is a module that provides support for serializing and deserializing Oracle JSON (OSON) data using Jackson APIs.
It includes custom generators, parsers, serializers, and deserializers for POJO mapping and Java types, ensuring efficient
JSON data handling in Oracle environments.
The module implements [**oracle.jdbc.spi.JsonProvider**](https://docs.oracle.com/en/database/oracle/oracle-database/23/jajdb/oracle/jdbc/spi/OsonProvider.html)
in order to use the Oracle JDBC driver's JSON processing capabilities. It, therefore, requires the **23.6** JDBC Thin Driver (or higher).
## Features
- **OSON Generators**: Custom logic for generating Oracle JSON (OSON) representations of Java objects.
- **OSON Parsers**: Parsing Oracle-specific JSON(OSON bytes) data into Java objects.
- **Serializers**: Custom serializers for transforming Java types into OSON bytes.
- **Deserializers**: Custom deserializers for mapping OSON bytes back into Java POJOs.
- **POJO Mapping**: Seamless mapping between Plain Old Java Objects (POJOs) and Oracle OSON formats.
- **Java Types Handling**: Support for various complex and basic Java types during serialization and deserialization.
- **Jackson Annotation support**: Support for Jackson Annotations. Note: When **@Format** annotation is used, the values are processed as Strings.

## Installation

All providers in this module are distributed as single jar on the Maven Central
Repository. The jar is compiled for JDK 8, and is forward compatible with later
JDK versions. The coordinates for the latest release are:
```xml
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-jackson-oson</artifactId>
<version>1.0.1</version>
</dependency>
```
## Building the provider module
1. Clone the repository:
```bash
git clone https://github.com/oracle/ojdbc-extensions.git
2. Navigate to the project directory:
```bash
cd ojdbc-provider-jackson-oson
3. Build the module and it's dependencies:
```bash
mvn clean -pl ojdbc-provider-jackson-oson -amd install

## Usage
Usage Examples for Oracle Jackson OSON Provider Extensions can be found at [ojdbc-provider-samples](../ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/oson/sample)

## Samples Explanation
- **[AccessJsonColumnUsingPOJOAndJsonProvider](../ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/oson/sample/AccessJsonColumnUsingPOJOAndJsonProvider.java)**:
Demonstrates the usage of the Jackson OSON provider to serialize a Plain Old Java Object (POJO) to OSON
bytes in order to save it in a JSON column in the database and deserialize OSON bytes to
POJO during retrieval. In this case, the JDBC Thin Driver invokes the provider to serialize/deserialize.
- **[AccessJsonColumnUsingHibernate](../ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/oson/sample/AccessJsonColumnUsingHibernate.java)**:
Performs the same task as above using Hibernate.
- **[AccessJsonColumnUsingJacksonObjectNode](../ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/oson/sample/AccessJsonColumnUsingJacksonObjectNode.java)**:
Demonstrates the usage of the Jackson OSON provider to serialize Jackson's ObjectNode
to OSON bytes for insertion and vice-versa for retrieval.
- **[AccessJsonColumnUsingPOJO](../ojdbc-provider-samples/src/main/java/oracle/jdbc/provider/oson/sample/AccessJsonColumnUsingPOJO.java)**:
Demonstrates how to use the Jackson OSON provider APIs to Serialize/Deserialize POJO and use JDBC
to directly insert the OSON bytes.


86 changes: 86 additions & 0 deletions ojdbc-provider-jackson-oson/example-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
################################################################################
# Copyright (c) 2024 Oracle and/or its affiliates.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or data
# (collectively the "Software"), free of charge and under any and all copyright
# rights in the Software, and any and all patent rights owned or freely
# licensable by each licensor hereunder covering either (i) the unmodified
# Software as contributed to or provided by such licensor, or (ii) the Larger
# Works (as defined below), to deal in both
#
# (a) the Software, and
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software (each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
# The above copyright notice and either this complete permission notice or at
# a minimum a reference to the UPL must be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################

# This file provides examples of properties that configure tests in this
# module.
#
# QUICK GUIDE TO RUNNING TESTS:
# 1. Create a copy of this file named "test.properties":
# cp example-test.properties test.properties
# 2. In test.properties, replace example values with real values (the file is
# .gitignore'd, so sensitive info won't be checked in to the repo)
# 3. Comment out any lines for which a value can not be provided (tests are
# skipped if no value is configured).
# 4. mvn clean verify
#
# CONFIGURING TEST PROPERTIES
# Test properties are read from a properties file by the TestProperties class.
# The TestProperties class can be found in:
# ojdbc-provider-common/src/testFixtures/java/oracle/jdbc/provider/TestProperties.java
# The default behavior of TestProperties is to read a file named
# "test.properties" in the current directory. A non-default location may be
# specified as a JVM system property:
# mvn clean verify -Doracle.jdbc.provider.TestProperties=/path/to/my-test.properties
#
# MAINTAINING THIS FILE
# Project maintainers should add an example to this file anytime they write a
# test which requires a new property. Not doing so will inflict pain and
# suffering upon our fellow programmers, and will also lead to increased
# maintenance costs.
#
# IGNORING UNCONFIGURED PROPERTIES
# No test should cause a build failure due to an unconfigured property.
# Using JUnit terminology: A test should "abort" rather than "fail" when a
# property is not configured. This means that the test does not pass, but it
# does not cause the build to fail either.
# Methods of the TestProperties class will automatically abort a test if a
# property is not configured. The org.junit.jupiter.api.Assumptions class may
# also be used directly to abort a test.
# There is NO environment in which ALL tests can be run. Some tests may
# require authentication as a managed identity in an Azure VM, while other
# tests require authentication as an instance principal in an OCI compute
# instance; These environments are mutually exclusive. This is one reason why
# tests can not fail the build if a required property is not set.
# A more practical reason is that developers may not need to run all tests if
# their changes are isolated to single module. For instance, a developer
# working on an OCI provider should not need to set up an Azure tenancy to test
# their changes.

JACKSON_OSON_URL=url
JACKSON_OSON_USERNAME=user_name
JACKSON_OSON_PASSWORD=pass_word
Binary file added ojdbc-provider-jackson-oson/file.json
Binary file not shown.
88 changes: 88 additions & 0 deletions ojdbc-provider-jackson-oson/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Oracle Jackson OSON Provider</name>

<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>${extensions-version}</version>
</parent>

<artifactId>ojdbc-provider-jackson-oson</artifactId>
<properties>
<jackson-version>2.18.1</jackson-version>
</properties>

<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-common</artifactId>
<version>${extensions-version}</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-common</artifactId>
<classifier>tests</classifier>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading
Loading