Hi Robert,

nice to see you're proceeding with the CROWD Literature app.
Here I want provide you a hint for designing your business service 

In your CrowdService implementation you have this method:

        public void updateEditablePerson(@PathParam("personId") long personId, 
String editablePersonJSON) {

JSON is meant only as a transport format. Your business service is supposed to 
abstract the transport and rely on 1st-class business objects instead, e.g. 
EditablePerson. Keep in mind your service methods are not only callable from 
remote, but also from within the same OSGi container. 
Serialization/Deserialization would be an unnecessary overhead in this case.

This would make a better business API:

        public void updateEditablePerson(@PathParam("personId") long personId, 
EditablePerson person) {

JSON-deserialization (in case of remote invocation) and EditablePerson 
instantiation is done by JAX-RS then, by the help of DM's standard JAX-RS 
providers (see module dm4-webservice). All you need to do is to implement a 
public EditablePerson constructor which expects a JSONObject as a parameter:

        public class EditablePerson ... {

                String firstName;
                String lastName;

                // this constructor is invoked by DM4 Webservice / JAX-RS
                public EditablePerson(JSONObject json) throws JSONException {
                        this.firstName = json.getString("firstName");
                        this.lastName = json.getString("lastName");

                public EditablePerson(String firstName, String lastName) {
                        this.firstName = firstName;
                        this.lastName = lastName;


A developer would invoke the 2nd constructor (which takes the values directly) 
when calling your updateEditablePerson() method locally, possibly from another 
DM module which consumes your CrowdService.


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

devel mailing list

Reply via email to