【发布时间】:2014-07-16 23:44:21
【问题描述】:
我不明白为什么注释对我的 GET REST API 没有任何作用。 我在所有类的供应商中都有 JMS 序列化程序.. 但是当我调用我的 web 服务时,会出现我的所有属性.. 而我做了一个 @ExlusionPolicy("all") 并且只是 ID 属性上的strong>@Expose..
这是我的实体产品:
<?php
namespace GroupeGC\Bundle\ProductBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Jms\Serializer\Annotation as JMS;
/**
* Product
*
* @ORM\Table(name="gc_product")
* @ORM\Entity
* @JMS\ExclusionPolicy("all")
*
*/
class Product
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @JMS\Type("integer")
* @JMS\Expose
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=255, nullable=false)
*/
private $code;
/**
* @var string
*
* @ORM\Column(name="label", type="string", length=255, nullable=true)
*
*/
private $label;
/**
* @var float
* @ORM\Column(name="volume", type="float")
*
*/
private $volume;
/**
* @var float
* @ORM\Column(name="weight", type="float")
*/
private $weight;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set code
*
* @param string $code
* @return Product
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set label
*
* @param string $label
* @return Product
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* Get label
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
public function getVolume() {
return $this->volume;
}
public function setVolume($volume) {
$this->volume = $volume;
return $this;
}
public function getWeight() {
return $this->weight;
}
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
但是我们可以看到,通常情况下,我应该有应该出现在我的 JSON 中的 id 属性,而我有所有属性.. 我不明白。
编辑 1:这是 app/config 中的 fos_rest 配置:
fos_rest:
view:
failed_validation: HTTP_BAD_REQUEST
default_engine: php
formats:
json: true
xml: true
format_listener:
prefer_extension: true
body_listener:
decoders:
json: fos_rest.decoder.json
xml: fos_rest.decoder.xml
routing_loader:
default_format: json
fos_js_routing:
routes_to_expose: [oro_*]
我认为这里没有问题..
【问题讨论】:
标签: php symfony fosrestbundle jmsserializerbundle