arangodb-java-driver icon indicating copy to clipboard operation
arangodb-java-driver copied to clipboard

Control over null values conversion during query execution

Open Magnastraw opened this issue 3 years ago • 3 comments

Hello, can you explain please, why do not we have a control over a null values conversion, when exection queries with java driver? https://github.com/arangodb/arangodb-java-driver/blob/67a54095469e1a095fd7204bc1c6c4605437e736/src/main/java/com/arangodb/internal/InternalArangoDatabase.java#L177 This is hardcoded behaviour

Magnastraw avatar May 05 '21 11:05 Magnastraw

:+1: I've got a similar issue but with deserialization.

val str = db.query("RETURN null", classOf[String]).next()
assert(str == null) // FAILS - actual result is a string "null"

That is counter intuitive and took me several hours to find a workaround like this:

val str = Option(db.query("RETURN null", classOf[Object]).next()
assert(str == null) // OK - now it returns null as expected, just needs to be casted to String

wajda avatar Oct 21 '21 23:10 wajda

Hi @wajda , this happens because deserializing to String is intended as deserializing to json string, except if the VPack being deserialized is a VPack String. This seems to me a bug, since also the case of VPack null value should be excluded. This should be fixed by https://github.com/arangodb/arangodb-java-driver/pull/411

rashtao avatar Oct 22 '21 08:10 rashtao

Thank you Michele for the quick turnaround!

wajda avatar Oct 22 '21 13:10 wajda

Fixed in https://github.com/arangodb/arangodb-java-driver/releases/tag/v7.0.0-ALPHA.1

rashtao avatar Jan 20 '23 10:01 rashtao

Since vertion 7.0.0, keepNull behavior can be specified using Jackson API by:

  • adding annotations on related fields, or
  • registering custom serializers

see https://github.com/arangodb/arangodb-java-driver/blob/v7/docs/v7_java-reference-serialization.md.

Furthermore, to read and write raw JSON strings a new wrapper class RawJson has been introduced, see https://github.com/arangodb/arangodb-java-driver/blob/v7/docs/v7_detailed_changes.md#user-data

https://github.com/arangodb/arangodb-java-driver/releases/tag/v7.0.0-RC.4

rashtao avatar Mar 21 '23 14:03 rashtao

Closing as fixed in version 7.0.0.

keepNull behavior can be specified using Jackson API by:

  • adding annotations on related fields, or
  • registering custom serializers

see https://github.com/arangodb/docs/blob/113c2351a0153171adfc74c313454af6bb5c7f08/drivers/java-reference-serialization.md.

Furthermore, to read and write raw JSON strings a new wrapper class com.arangodb.util.RawJson has been introduced, see https://github.com/arangodb/docs/blob/113c2351a0153171adfc74c313454af6bb5c7f08/drivers/java-changes-v7.md#user-data

rashtao avatar Apr 20 '23 12:04 rashtao