My consumed XML API has an option to retrieve only parts of the response.
This causes the resulting object to have a lot of NULL
properties if this feature is used.
Is there a way to actually skip NULL
properties? I tried to implement an exclusion strategy with
shouldSkipProperty(PropertyMetadata $property, Context $context)`
but i realized there is no way to access the current property value.
An example would be the following class
class Hotel {
/**
* @Type("string")
*/
public $id;
/**
* @Type("integer")
*/
public $bookable;
/**
* @Type("string")
*/
public $name;
/**
* @Type("integer")
*/
public $type;
/**
* @Type("double")
*/
public $stars;
/**
* @Type("MssPhp\Schema\Response\Address")
*/
public $address;
/**
* @Type("integer")
*/
public $themes;
/**
* @Type("integer")
*/
public $features;
/**
* @Type("MssPhp\Schema\Response\Location")
*/
public $location;
/**
* @Type("MssPhp\Schema\Response\Pos")
*/
public $pos;
/**
* @Type("integer")
*/
public $price_engine;
/**
* @Type("string")
*/
public $language;
/**
* @Type("integer")
*/
public $price_from;
}
which deserializes in this specific api call to the following object with a lot of null
properties.
"hotel": [
{
"id": "11230",
"bookable": 1,
"name": "Hotel Test",
"type": 1,
"stars": 3,
"address": null,
"themes": null,
"features": null,
"location": null,
"pos": null,
"price_engine": 0,
"language": "de",
"price_from": 56
}
]
But i want it to be
"hotel": [
{
"id": "11230",
"bookable": 1,
"name": "Hotel Test",
"type": 1,
"stars": 3,
"price_engine": 0,
"language": "de",
"price_from": 56
}
]