Shisoft
Shisoft

Reputation: 4245

How to add class name when serialize to json by net.sf.json

I am planning to provide a interface to iOS Apps, the developer asked to add an additional field call class contains the name of the pojo I used on server so he can convert to his class on client easily. The problem is I have to do this when the json lib is processing the values.I think the registerJsonValueProcessor can do the trick. I got then class name by obj.getClass().getName() but I still have no idea how to attach it to json-lib.

Upvotes: 3

Views: 247

Answers (1)

Naveen Ramawat
Naveen Ramawat

Reputation: 1445

If you are using jackson for serialization/deserialization of json than please apply the annotation JsonTypeInfo on your class. It could help you
@JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")

Upvotes: 0

Related Questions