在Symfony 4中,我使用symfony/serialize
r将对象规范化为数组:
$encoders = [new JsonEncoder()];
$normalizers = [new ObjectNormalizer(null,null)];
$this->serializer = new Serializer($normalizers, $encoders);
$normalized = $this->serializer->normalize($user); // this normalize user and change the prop name to dateOfCreation
我的用户Entity
如下:
class User {
/**
* @ORM\Column(type="datetime", nullable=true)
* @SerializedName("date_of_creationo")
*/
private date_of_creation;
}
如何禁用camelCase转换?
答案 0 :(得分:0)
您可以尝试将CamelCaseToSnakeCaseNameConverter用作规范化器
$normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter());