Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON array serialisation with 'null' member #8531

Closed
mjoa opened this issue Sep 13, 2018 · 4 comments
Closed

JSON array serialisation with 'null' member #8531

mjoa opened this issue Sep 13, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@mjoa
Copy link

mjoa commented Sep 13, 2018

OrientDB Version: 3.0.5

Java Version: 1.8

OS: macOS 10.13

Expected behavior

Creating a correct JSON document.

Actual behavior

If a provided JSON document contains an array and the last member in an array element is null the JSON document is not correctly processed. It looks like the ORecord.fromJSON(String iJson) which goes down to ORecordSerializerJSON.fromString(String iSource, ORecord iRecord, final String[] iFields) doesn't handle it correctly.

Example:

{
  "id": "f743507f-893f-417f-83a1-bb0db830c865",
  "list": [
    {
      "prop1": "val1",
      "prop2": null
    },
    {
      "prop": "val"
    }
  ]
}

Steps to reproduce

Create a new OElement and call the fromJSON(String iJson) method with a JSON document containing an array having a null member in last position of an array item.

private String odbAndBack(String id, String json) {
    try (ODatabaseSession session = dbPool.acquire()) {
        session.newElement("JsonTestGeneric").fromJSON(json).save();
        OResultSet rs = session.query(String.format("SELECT * FROM `JsonTestGeneric` WHERE `id` = '%s'", id));
        if (rs.hasNext()) {
            return rs.next().toJSON();
        }
    }
}

Input

{
  "id": "f743507f-893f-417f-83a1-bb0db830c865",
  "list": [
    {
      "prop1": "val1",
      "prop2": null
    },
    {
      "prop": "val"
    }
  ]
}

Output

{
  "@type": "d",
  "@rid": "#49:0",
  "@version": 1,
  "@class": "JsonTestGeneric",
  "id": "f743507f-893f-417f-83a1-bb0db830c865",
  "list": [
    {
      "prop1": "val1",
      "prop2": null
    },
    false
  ]
}

The behaviour is at least reproducible with orientdb-client version 3.0.5, 3.0.6 and 3.0.7.

A simple JUnit test case:
odb-json-test.zip

@luigidellaquila
Copy link
Member

Hi @mjoa

Thank you very much for pointing it out, I'll check it ASAP

Luigi

@mjoa
Copy link
Author

mjoa commented Sep 13, 2018

Hi @luigidellaquila
thanks for your quick response. I appreciate your help with this!
I had another look and changed the example code to have a look at the OElement being filled from the ORecordSerializerJSON.

try (ODatabaseSession session = dbPool.acquire()) {
    OElement element = session.newElement("JsonTestGeneric").fromJSON(json);
    element.save();
}

The element itself looks pretty good. So the problem might go down to the ODocument.save() method.

oelement-view

Just to have that said, the 'manual' insert works as expected.

INSERT INTO JsonTestGeneric content { "id": "f743507f-893f-417f-83a1-bb0db830c865", "list": [ { "prop1": "val1", "prop2": null }, { "prop": "val" } ] }

@luigidellaquila
Copy link
Member

Hi @mjoa

I found the problem (it was at a much lower level, on disk serialization) and fixed it. The fix will be released with v 3.0.8

Thanks

Luigi

@mjoa
Copy link
Author

mjoa commented Sep 13, 2018

Thanks @luigidellaquila for your support! Great you could fix it that fast. We looking forward to the upcoming version.

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

No branches or pull requests

2 participants