[BUG] 2.0.57 Deserialize an optional null parameter deserealize as empty string
This is a bug of the fastjson2 version 2.0.57. With the previous version (2.0.56) it works as expected.
Given the following json:
{
"bundleProductSummaries": [{
"detail": {
"colors": [
{
"certifiedMaterials": {
"show": false,
"materials": []
}
},
{
"certifiedMaterials": {
"show": false,
"materials": []
}
},
{
"certifiedMaterials": {
"show": false,
"materials": []
}
}
]
}
}]
}
Consider the following test:
@Test
void productBrandsProduct() {
var is = this.getClass().getResourceAsStream("/ProductBrandsProduct.json");
ProductBrandsProduct dto = JSON.parseObject(is, ProductBrandsProduct.class);
assertThat(dto).isNotNull();
assertThat(dto.getBundleProductSummaries().get(0).getDetail().getColors().get(0).getCertifiedMaterials().getContainsAtLeastTitle())
.isNull();
}
Note that 'containsAtLeastTitle' is not included at the json as it is an optional attribute.
The test fails because getContainsAtLeastTitle="" (empty string).
The test works well with the previous version 2.0.56
I have attached the following project with the given test:
Thank you for your feedback. I'll go research it.
Hi @JordiMartinezVicent, It looks fixed on 2.59.0, even when this issue is still open now - I just tested it now. Let's talk internally on Teams on monday. Regards,