Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Information lost #15

@carmnu

Description

@carmnu

Hi, thanks for your work.
I think I've found a bug in your lib.

If I deserialize the following json string (it's a post tree where "referred" are the medias that the post contains (I striped out unnecessary information)) using JSOG I lost some information.
In the specific I noticed that I lost the object related to the media with id 565 that in the original json string has a <"@ref":"8">.
If you take a look at the data you can see that in it there is the object with <"@id":"8">.

jsog-bug

Here is the code of the test:

var data = {"post":{"@id":"1","id":577,"ownerEntity":{"@id":"2","id":558,"language":{"@id":"3","id":12},"profilePicture":{"@id":"4","id":562,"ownerEntity":{"@ref":"2"}},"coverPicture":{"@id":"5","id":563,"ownerEntity":{"@ref":"2"}}},"referred":{"565":{"@ref":"8"},"572":{"@id":"6","id":572,"ownerEntity":{"@ref":"2"},"referer":{"568":{"@ref":"14"},"577":{"@ref":"1"},"587":{"@id":"22","id":587,"ownerEntity":{"@ref":"2"},"referred":{"572":{"@ref":"6"}}},"590":{"@ref":"12"},"591":{"@id":"7","id":591,"ownerEntity":{"@ref":"2"},"referred":{"565":{"@id":"8","id":565,"ownerEntity":{"@ref":"2"},"referer":{"577":{"@ref":"1"},"588":{"@id":"9","id":588,"ownerEntity":{"@ref":"2"},"referred":{"565":{"@ref":"8"}}},"591":{"@ref":"7"}},"picture":{"@id":"10","id":564,"ownerEntity":{"@ref":"2"}}},"569":{"@ref":"13"},"572":{"@ref":"6"},"579":{"@id":"11","id":579,"ownerEntity":{"@ref":"2"},"referer":{"577":{"@ref":"1"},"589":{"@id":"20","id":589,"ownerEntity":{"@ref":"2"},"referred":{"579":{"@ref":"11"}}},"590":{"@id":"12","id":590,"ownerEntity":{"@ref":"2"},"referred":{"569":{"@id":"13","id":569,"ownerEntity":{"@ref":"2"},"referer":{"568":{"@id":"14","id":568,"ownerEntity":{"@ref":"2"},"referred":{"567":{"@id":"16","id":567,"ownerEntity":{"@ref":"2"},"referer":{"568":{"@ref":"14"},"586":{"@id":"17","id":586,"ownerEntity":{"@ref":"2"},"referred":{"567":{"@ref":"16"}}}},"picture":{"@id":"18","id":566,"ownerEntity":{"@ref":"2"}}},"569":{"@ref":"13"},"572":{"@ref":"6"},"593":{"@id":"15","id":593,"ownerEntity":{"@ref":"2"},"referer":{"568":{"@ref":"14"}}},"594":{"@id":"19","id":594,"ownerEntity":{"@ref":"2"},"referer":{"568":{"@ref":"14"}},"picture":{"@ref":"15"}}},"replies":{"590":{"@ref":"12"}}},"590":{"@ref":"12"},"591":{"@ref":"7"}}},"572":{"@ref":"6"},"579":{"@ref":"11"}},"father":{"@ref":"14"}},"591":{"@ref":"7"}},"picture":{"@id":"21","id":578,"ownerEntity":{"@ref":"2"}}}}}},"picture":{"@id":"23","id":571,"ownerEntity":{"@ref":"2"}}},"579":{"@ref":"11"}}}};

var objectID = {};
var objectREF = {};
function getObjectIdRef(object) {
    for (var key in object) {
    if (key == '@id')
        objectID[object[key]] = object[key];
    else if (key == '@ref')
        objectREF[object[key]] = object[key];
    else if (object[key] !== null && typeof object[key] === 'object')
        getObjectIdRef(object[key]);
    } 
}

getObjectIdRef(data);
console.log('data: ' + JSON.stringify(data));
console.log('data: %O\t\tJSOG.decode(data): %O\t\t@id: %O\t\t@ref: %O', data, JSOG.decode(data), objectID, objectREF);

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions