문제

Suppose I have an entity with a single field: 'userName' whos corresponding column name in the table is 'user_name'. When I serialize object of that entity, it returns a json with column name of the userName field like this:

{"user_name": "davit"}

but what I want is for jms serializer to use entity field name (userName) as the json key:

{"userName": "davit"}    

Is this doable?

I read a lot of articles beginning with the documentation, but failed to find a reference to this...

Thanks a lot for help

도움이 되었습니까?

해결책

Not sure if you use annotations but you can use @serializedName

http://jmsyst.com/libs/serializer/master/reference/annotations#serializedname

다른 팁

I don't know which configuration format you're using (XML, YAML or Annotations) but they all have a serialized_name setting that allows you to configure the serialized name of a property.

It's @serializedName if you use annotations, serialized_name if you use YAML and serialized-name if you use XML.

The documentation contains reference (example) configurations in all formats.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top