首先,对我的英语感到抱歉..我会尽力用更好的方式表达。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