Reputation: 12424
In Google App Engine, I've got an object/model on the server. Let's call that "Car". Now the "Car" object has several properties ("Model", "Year", etc.). I want to pass information of the "Car" object from the server to the client, including some (if not all) of it's properties. One option is to have the "Car" object defined fully on both the client and the server, by sharing the model on both, but this is more than I need. Another is to define a client version of the model, but this leads to confusion between the two models and really I just want some of the properties of the model. So likely I'd just want to pass back the few pieces of information I want. I know one method I could do this by is converting the information to a json string and passing it. However, I'm not sure if this is the preferred method or if there are downsides to this. Does App Engine have a preferred way to pass this kind of information? What are the disadvantages of passing the information in a json string? Is there another method with the same advantages as a json string but without this disadvantages? Thank you much!
Upvotes: 0
Views: 52
Reputation: 1512
There are no preferred ways, whatever works best for your application. Manual (de)serialization from/to JSON seems like an overkill to me. What I usually do is create a wrapper class and place it in a package shared by both the client and the server. To make the code easier to maintain, I tend to (i.e. whenever possible) define a constructor that receives the underlying object and extracts the desired sub-set of properties, make the wrapper object immutable, etc.
Upvotes: 4