Jms反序列化xml setter不工作,但它与json工作正常

时间:2016-01-27 10:57:08

标签: xml jms deserialization

请帮我解决下一期:

$data = $this->_jmsSerializer->deserialize('<INF_NEW OKPO="null"></INF_NEW>', 'Entity\InfNew', 'xml');

注解:

/**
     * @JMS\Accessor(getter="getOKPO",setter="setOKPO")
     * @JMS\Type("string")
     * @JMS\Groups({"INF_NEW"})
     * @JMS\SerializedName("OKPO")
     * @JMS\XmlAttribute
     */
    private $_OKPO;

Getter和Setter:

public function setOKPO($OKPO)
    {
        $this->_OKPO = 'test';
    }

    /**
     * @return mixed
     */
    public function getOKPO()
    {
        return 'test';
    }

转储$ data的结果:  -_OKPO:“null”

可是:

$data = $this->_jmsSerializer->deserialize('{"OKPO":"null"}', 'Entity\InfNew', 'json');

转储$ data的结果:  -_OKPO:“测试”

0 个答案:

没有答案