Skip to content

JsonObject is turning empty objects into empty arrays #24

@jaaufauvre

Description

@jaaufauvre

Hi,

The JsonObject class turns empty objects into empty arrays and thus is unable to give back the original JSON representation.

For example:

{
 "item1": {},
 "item2": {}
}

Is returned as:

{
 "item1": [],
 "item2": []
}

Here is how to reproduce it:

 public function test() {
        $this->assertEquals('[{"item":"value"}]', (new JsonObject('[{"item":"value"}]'))->getJson());
        $this->assertEquals('{"item":"value"}', (new JsonObject('{"item":"value"}'))->getJson()); 
        $this->assertEquals('[]', (new JsonObject('[]'))->getJson());
        $this->assertEquals('{}', (new JsonObject('{}'))->getJson());  // FAILS!
    }
Failed asserting that two strings are equal.
Expected :'{}'
Actual   :'[]'

Best regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions