ODocument.toJSON broken when ODocument contains null linked records
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 .)
What release?
It's version 2.0, startup log info:
OrientDB Server v2.0 (build UNKNOWN@r${buildNumber}; 2015-01-20 16:41:17+0000)
@lvca : Will the fix in 54f7315c6b83bf6c1e634318d13e6dfa7fb709a3 result in:
{"@rid":"#13:0","@version":1,"linkedId":null,"name":"Item1","fieldB":null}, or{"@rid":"#13:0","@version":1,"name":"Item1","fieldB":null}? Similarly, what willODocument.field("linkedId")return? In v2.0,field()is inconsistent withtoJSON():doc.field("linkedId")returns theORecordId #-1:-1rather thannull.
*edit: somehow, two versions of the final sentence were in the comment.
Record id #-1:-1 means no link, so it's pretty the same. How this cause a problem on your use case?
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.
Fixed!