Skip to content

_metadata from JSON Relational Duality View not properly deserialized #164

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

Open
simasch opened this issue Dec 28, 2024 · 3 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@simasch
Copy link

simasch commented Dec 28, 2024

I created an example project using Oracle JSON Relational Duality View and oracle-spring-boot-starter-json-collections.
https://github.com/simasch/oracle-json-relational-duality-view (Branch: etag)

The class PurchaseOrder also mapps the Metadata. But the etag and the asof values are no properly deserialized:

Screenshot 2024-12-28 at 14 08 42

Is there something wrong with my setup?

@andytael andytael added the bug Something isn't working label Dec 28, 2024
@anders-swanson
Copy link
Member

Hi @simasch,

Thanks for sharing this, I'm taking a look.

@anders-swanson
Copy link
Member

@simasch, this is a bug in the JDBC driver. I suggest using the following work-around until the bug is fixed:

Implement a custom deserializer for OracleJsonBinary:

import java.lang.reflect.Type;
import java.sql.SQLException;
import java.util.HexFormat;

import jakarta.json.JsonValue;
import jakarta.json.bind.JsonbException;
import jakarta.json.bind.serializer.DeserializationContext;
import jakarta.json.bind.serializer.JsonbDeserializer;
import jakarta.json.stream.JsonParser;
import oracle.sql.json.OracleJsonBinary;

public class RawDeserializer implements JsonbDeserializer<String> {
    @Override
    public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
        try {
            JsonValue value = parser.getValue();
            OracleJsonBinary ovalue = ((java.sql.Wrapper) value).unwrap(OracleJsonBinary.class);
            byte[] raw = ovalue.getBytes();
            return HexFormat.of().withUpperCase().formatHex(raw);
        } catch (SQLException e) {
            throw new JsonbException(e.getMessage(), e);
        }
    }
}

Next, annotate the fields in your Metadata class with @JsonbTypeDeserializer, using the custom RawDeserializer class:

import jakarta.json.bind.annotation.JsonbTypeDeserializer;

public class Metadata {
    @JsonbTypeDeserializer(RawDeserializer.class)
    private String asof;
    @JsonbTypeDeserializer(RawDeserializer.class)
    private String etag;
   
   // getters, setters, etc.
}

Note the use of the custom deserializer is only required for raw types, like those in the metadata object.

I'll keep this issue open until Spring Cloud Oracle is able to uptake a fixed JDBC driver version 👍

@simasch
Copy link
Author

simasch commented Jan 3, 2025

Hi @anders-swanson
This works. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants