Skip to content

Invalid Json fetched from jv_snapshot.state column oracle sql database #1055

Description

@WojtekPWas

Clear description of my expectations versus reality

We have got recently an error
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 3 path $
at com.google.gson.Gson.assertFullConsumption(Gson.java:864) ~[gson-2.8.2.jar!/:na]
at com.google.gson.Gson.fromJson(Gson.java:854) ~[gson-2.8.2.jar!/:na]
at com.google.gson.Gson.fromJson(Gson.java:802) ~[gson-2.8.2.jar!/:na]
at com.google.gson.Gson.fromJson(Gson.java:774) ~[gson-2.8.2.jar!/:na]
at org.javers.core.json.JsonConverter.fromJsonToJsonElement(JsonConverter.java:70) ~[javers-core-3.10.2.jar!/:na]

The reason was in line 22 in org/javers/repository/sql/finders/CdoSnapshotMapper.java (javers-persistence-sql module)
.withSnapshotState(resultSet.getString(SNAPSHOT_STATE))
The method withSnapshotState in CdoSnapshotSerialized class gets string as a parameter. This parameter has a value, which in debugger looks very similar to
https://stackoverflow.com/questions/46198533/java-sql-resultset-getstring-returns-string-with-extra-characters

Contents of column state (of type CLOB) in the table jv_snapshots in the Database (retrieved with SQL Developer tool) looks ok.

Method getString is not the right way to retrieve data from the CLOB column, although it brings correct results in most cases.

The solution was to use getClob method as described in https://stackoverflow.com/questions/19486648/how-to-retrive-the-clob-value-from-oracle-using-java/19486749.

I prepared custom Javers version basen on 3.10.2 and the problem disappeared.

I looked at the current version of Javers 5.14.0. getString(SNAPSHOT_STATE) is still there.
That is why I suggest the issue. Of course I would like to contribute and implement it in the current javers version.

Steps To Reproduce
I have no idea how to produce test case. Problem arise with fetching data from the database. The data is correct. STATE column of problematic row contains many characters, but there were cases with more characters and no error. I suppose the problem has to do with how Oracle Server maintains the data, that data not necessarily occupy continuous space.

Javers' Version
3.10.2
5.14.0 contains invalid method call getString(SNAPSHOT_STATE)

Additional context
The error was reported after 2 years of production use of the system. Table jv_snapshot contains more than 36 milion rows.

In our next project we will use current javers version. I find Javers well designed, easy to use and powerful.

Best regards
Wojtek Wąs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions