Php JMS序列化程序反序列化嵌套对象
我正在使用: 用于反序列化json对象。 目前我有:Php JMS序列化程序反序列化嵌套对象,php,json,symfony,serialization,Php,Json,Symfony,Serialization,我正在使用: 用于反序列化json对象。 目前我有: /** * @param int $id * @return Customer * @throws \Http\Client\Exception */ public function get(int $id): Customer { $response = $this->client->get('/customers/' . $id); $data = json_encode(json_decode(
/**
* @param int $id
* @return Customer
* @throws \Http\Client\Exception
*/
public function get(int $id): Customer
{
$response = $this->client->get('/customers/' . $id);
$data = json_encode(json_decode(
$response->getBody()->getContents()
)->data->attributes);
return $this
->serializer
->deserialize($data, Customer::class, 'json');
}
我在这里收到的json如下所示:
{
"data": {
"type": "customer",
"id": "4356456",
"links": {
"self":"https:\/\/api.ecurring.com\/customers\/345656"
},
"attributes": {
"gender": "m",
"first_name": "Laurens"
}
}
$data = json_encode(json_decode(
$response->getBody()->getContents()
)->data->attributes);
是否可以告诉JMS它应该自动从data->attributes
开始,而不是像这样做:
{
"data": {
"type": "customer",
"id": "4356456",
"links": {
"self":"https:\/\/api.ecurring.com\/customers\/345656"
},
"attributes": {
"gender": "m",
"first_name": "Laurens"
}
}
$data = json_encode(json_decode(
$response->getBody()->getContents()
)->data->attributes);
您可以检查排除策略 阅读文档,它真的很有帮助
和您可以检查排除策略 阅读文档,它真的很有帮助 及