I'm not sure if this helps, but I had a similar problem. In my scenario, I need a web service that was supposed to get a bunch of values ββthat were organized as a kind of profile. But this service has to cope with the fact that there are more profiles where still old customers use this service. The interface should be as static as possible.
Our solution is very simple. We publish only one text field as the content of the message. But this includes the serialized state of the profile object in JSON. Pseudocode:
public class Profile1 { ... public String asJSON() { JSONObject obj = new JSONObject(); obj.put("profileAtr1", profileAtr1); ... return obj.toString() } } formParams.put("profile", profile.asJSON()); client.post(formParams);
Thus, it does not automatically deserialize, but it is easy to do it manually. We do this with a generic Profile object that can be created from a JSON String in the constructor. Pseudocode:
public GenericProfile { public GenericProfile(String json) { JSONObject obj = new JSONObject(json); String profileName = obj.getString("profileName"); if (profileName.equals("Profile1") { this = new Profile1(obj);
And then in your web service there is only one form parameter for processing and deserialization;) Pseudocode:
public ResponseEnvelope coolServiceFunction(@FormParam("profile") String profileData) { GenericProfile profile = new GenericProfile(profileData); if (profile instanceof Profile1) { do what you want } }
Sorry for the pseudo-code, but I have alleady shutdown my dev vm and no longer have access to any repository :( I think the biggest advantages of this solution are: 1. It can transport everything that you can package in JSON. Thus, I I transmit BASE64 encoded binary blocks and highly encrypted text data 2. The simplest example of a POST REST Framework tutorial will provide everything you need to do 3. You can be sure that your interface will remain for a long period of time.
Hope that helps
source share