Customized attributes in JSON
Dear all, I'm new to JMS, got a question that I need some help on.
Suppose I have a model that has fields A and B. So serializing that gives only id, A and B, what if I want to expose as a JSON a field C (which is NOT attribute) and is a function of A and B?
e.g. {"A":2, "B":4, "C":16} , where C is A^B.
Something like that.
Thanks!!!
This is not possible atm.
You need to create either a) a property for C or b) write a custom handler for your object.
Hi @schmittjoh
Thanks for swift response. I didn't clearly understand so I want to repeat to see if I'm right on this: a) create a property that will be updated on a @PreSerialize event? b) what's the custom handler you mean? Sorry, could you elaborate a bit?
Thanks!
@schmittjoh couldn't it be possible if you have a getter for C in the class ?
You would still need the property to declare an @Accessor annotation on it.
On Tue, Mar 13, 2012 at 1:03 PM, Christophe Coevoet < [email protected]
wrote:
@schmittjoh couldn't it be possible if you have a getter for C in the class ?
Reply to this email directly or view it on GitHub:
https://github.com/schmittjoh/JMSSerializerBundle/issues/91#issuecomment-4483019