_metadata from JSON Relational Duality View not properly deserialized
simasch opened this issue · 3 comments
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:
Is there something wrong with my setup?
Hi @simasch,
Thanks for sharing this, I'm taking a look.
@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 👍
Hi @anders-swanson
This works. Thank you!