If you use the Jackson JSON processor http://jackson.codehaus.org/ to translate the POJO model code into JSON, you do not need to recreate any properties on your base model. A simple example:
public String getPerson(){
Person personPOJOInstance = new Person();
ObjectMapper mapper = new ObjectMapper();
StringWriter sw = new StringWriter();
try{
mapper.writeValue(sw, personPOJOInstance);
pojoJSON = sw.getBuffer().toString();
}
catch(IOException exc){
}
return pojoJSON;
}
You don’t even have to worry about this if you use a Spring MVC controller and mark your controller method with the following @RequestMapping annotation, for example:
@RequestMapping(method= RequestMethod.GET, produces = "application/json", value="/path/to/controller/method")
public @ResponseBody getPerson(){
return new Person();
}
, :
var Person = Backbone.Model.extend({
url: '/path/to/controller/method'
});
- Backbone, .
, , , POJO Backbone, :
var person = new Person();
person.fetch();
...
var name = person.get('name');