質問

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