私の消費したXML APIには、応答の一部だけを取得するオプションがあります。 この機能を使用すると、結果として得られるオブジェクトは多くのNULL
プロパティを持ちます。 NULL
プロパティを実際にスキップする方法はありますか?JMSシリアライザのnullプロパティを除外
shouldSkipProperty(PropertyMetadata $property, Context $context)`
で除外戦略を実装しようとしましたが、現在のプロパティ値にアクセスする方法がないことがわかりました。
例は、以下のクラスnull
特性の多くでは、次のオブジェクトに、この特定のAPIコールにデシリアライズ
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;
}
あろう。
"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
}
]
しかし、私はあなたがそうのようなnull
性質スキップするJMSシリアライザを構成することができ、それは
"hotel": [
{
"id": "11230",
"bookable": 1,
"name": "Hotel Test",
"type": 1,
"stars": 3,
"price_engine": 0,
"language": "de",
"price_from": 56
}
]
私は実際にこれを試しましたが、シリアライゼーションではなく、デシリアライズでは機能しているようです。 –
デシリアライズ時にnullプロパティをスキップする方法を教えてください。データがない場合はnullになります。 –
本当に妥当な音です。だから私の唯一のオプションは、再帰的にすべてのnullプロパティをフィルタリングすることです私はデシリアライズされたオブジェクトを取得した後に? –