Open alemures opened 6 years ago
I agree, it should just return an empty object. Is that what you are thinking? I mean like this:
var obj = {
a: 'b'
};
var expect = {
};
var map = {
z: 'a.b'
};
om(obj, map); // --> {}
Yep, i may have a chance to try to fix it through the weekend ;).
I have actually a solution for this weird behaviour but, one of the previous tests have been broken. The broken test is called "map object to another - prevent null values from being mapped", and it's exactly reproducing the behaviour we want to remove when an empty object is created even if it doesn't match a key on "map" object.
That's the code of the broken test:
var obj = {
"a" : 1234,
"foo": {
"bar": null
}
};
var expect = {
foo:{
a:1234
},
bar:{
}
};
var map = {
'foo.bar' : 'bar.bar',
'a': 'foo.a'
};
Based on what we spoke, the key "bar:{}" should not be expected so, i suggest that a change in that specific test is necessary in order to add this update along with a version bump.
Any thoughts about that?
Hi there. Checking to see if this issue has been fixed or if there is a valid work around?
I added this test to my branch. My expectation differs from yours though:
var expect = {
foo:{
a:1234
}
};
Note that ObjectMapper does not store any key that has a NULL value, unless the null
key is set to true
in object notation. If you think differently, please let me know and this can be debated.
The following code produces an empty object as result:
I think it's an unexpected behavior, what do you think?