首先,對我的英語感到抱歉..我會盡力用更好的方式表達。JMS反序列化JSON並適合模型類
我正在使用JMSSerializerBundle在Symfony 2.7中構建API Rest。 我得到了與地址屬性分開的客戶模型:(一號線,2號線,城市,POSTAL_CODE,州,COUNTRY_CODE),當我發送的響應,我這樣做:
{
"company_name": "Foograde",
"first_name": "Federico",
"last_name": "Balderas Mata",
"email": "[email protected]",
"address": {
"line1": "Gral. Ortega #223D",
"city": "Celaya",
"state": "Guanajuato",
"postal_code": "38010",
"country_code": "MX"
}}
就像你看到的,我是一個地址對象發送參數:
/**
* Get address
* @VirtualProperty
* @return array
* @SerializedName("address")
*/
public function getAddress()
{
return array(
'line1' => $this->line1,
'line2' => $this->line2,
'line2' => $this->line3,
'city' => $this->city,
'state' => $this->state,
'postal_code' => $this->postal_code,
'country_code' => $this->country_code
);
}
但現在我想要做的就是在同一形式的請求,有一個地址對象和分離特性將其插入到數據庫中。
有什麼想法?
我真的不明白你想要什麼,但至少我猜[驗證,序列化和映射json請求以建模類](http://www.inanzzz.com/index.php/post/nx2b/validating- serialising-and-mapping-json-request-to-model-classes)將會派上用場。也可能是該網站中的其他映射和建模示例。 – BentCoder