orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

ODocument.toJSON broken when ODocument contains null linked records

Open buzzkillington opened this issue 11 years ago • 6 comments

In v2.0, ODocument.toJSON is not handling (at least) the case of a null linked record field correctly. The way OJSONFetchContext.onBeforeDocument and OJSONFetchContext.writeSignature are implemented, the following data

----+-----+------+--------+-----+------
#   |@RID |@CLASS|linkedId|name |fieldB
----+-----+------+--------+-----+------
0   |#13:0|Blah  |#-1:-1  |Item1|null
----+-----+------+--------+-----+------

gets written as invalid JSON when calling toJSON(), due to the format of "linkedId" (null should not be surrounded by '{}'):

{"@rid":"#13:0","@version":1,"linkedId":{null},"name":"Item1","fieldB":null}

(Possibly related to issue #3348 .)

buzzkillington avatar Jan 22 '15 22:01 buzzkillington

What release?

lvca avatar Jan 22 '15 22:01 lvca

It's version 2.0, startup log info:

OrientDB Server v2.0 (build UNKNOWN@r${buildNumber}; 2015-01-20 16:41:17+0000)

buzzkillington avatar Jan 22 '15 23:01 buzzkillington

@lvca : Will the fix in 54f7315c6b83bf6c1e634318d13e6dfa7fb709a3 result in:

  1. {"@rid":"#13:0","@version":1,"linkedId":null,"name":"Item1","fieldB":null}, or
  2. {"@rid":"#13:0","@version":1,"name":"Item1","fieldB":null}? Similarly, what will ODocument.field("linkedId") return? In v2.0, field() is inconsistent with toJSON(): doc.field("linkedId") returns the ORecordId #-1:-1 rather than null.

*edit: somehow, two versions of the final sentence were in the comment.

buzzkillington avatar Jan 26 '15 20:01 buzzkillington

Record id #-1:-1 means no link, so it's pretty the same. How this cause a problem on your use case?

lvca avatar Jan 27 '15 07:01 lvca

I identified the inconsistency because I'm working around this toJSON() bug with manual ODocument/JSON conversions in my API (using field() calls) and found that I now need to also include a special case to replace the "placeholder" #-1:-1 with null. Since Orient represents other null fields with null returned from both field() and toJSON(), it seems like consistently returning null in the case of "no link" (from both field() and toJSON()) would be preferable.

buzzkillington avatar Jan 27 '15 16:01 buzzkillington

Fixed!

lvca avatar Jan 28 '15 00:01 lvca