Closed devpreview closed 7 years ago
I'm curious, the "Before" looked like normal behaviour to me. Maybe I misunderstood, but if a field is completely absent from a JSON file we're trying to deserialize, why should it return a value in the TS object ? The issue #10 is indeed about a behaviour that is wrong to me, but this is not the use case described in this issue. I'm confused.
@Orhleil I think is that the behavior should not depend on the input JSON.
@Orhleil Maybe you're right.
I fix this bug:
class TestObject {
@JsonProperty()
public field: string[];
}
let json = {
'field': []
};
let result = ObjectMapper.deserialize(TestObject, json);
Array.isArray(result.field); // return false, 'result.field' is undefined
I think that the correct behavior is:
class TestObject {
@JsonProperty()
public field: string[];
}
ObjectMapper.deserializeArray(TestObject, {}); // return `undefined` or thrown error
ObjectMapper.deserializeArray(TestObject, []); // return empty array
let result = ObjectMapper.deserialize(TestObject, {});
// result.field is undefined or thrown error
let result = ObjectMapper.deserialize(TestObject, { `field`: [] });
// result.field is empty array
Before:
After: