I’ve created a small web service that returns some json, and the returned json value looks like:
[{"class":"simple.web.service.Stock","id":null,"name":"GOOG","price":123.45}, {"class":"simple.web.service.Stock","id":null,"name":"APPL","price":345.67}]
My object does not contain an id field. Where does that come from? And how should it be populated?
Also, is included the class field standard? What if I don’t want to include that?
The
idattribute is created by default on domain objects, just likeversion(unless you specifically tell it not to includeversion). Both are set up and maintained automatically under normal usage. You can control how the id is created/populated if you want – see the manual.The JSON constructor does not return the actual id or version by default for security reasons. To include them or to not include other items you will probably need to create custom JSON marshallers.
Something like this in your Bootstrap to only include
nameandprice:}