JsonMappingException - variable Model Class
===

I am building an app that use the jackson library to communicate with an API and format JSON objects to send them back to the UIThreads.
    
        

    public class User {
           protected String id;
            protected GregorianCalendar registredAt;
            protected String username;
            protected Team team;
            [...]
            	
            public User(HashMap<String, Object> attributes) {
            	this.id = (String) attributes.get("id");
            	this.registredAt = (GregorianCalendar) attributes.get("registredAt");
            	this.username = (String) attributes.get("username");
            	this.team = (Team) attributes.get("team");
            }
    }

So, I've got a class constructor that initialize my Object my an HashMap instance, that I would get back from my Json API callback.


I succeed to send a POST call to my API with HttpURLConnection and receive a nice Json callback.
Then, I would like to init an object with the JsonParser received and send it to the current UIThread with an handler.

The problem is that I have made an helper class to manage all my API calls, and I do not want to precise the class I could use to init my object with the jackson object's mapper...

    response = objectMapper.readValue(callbackParser, User.class)

So, responseClass will be a variable class instance, of a custom class like User or something else...
-->

    response = objectMapper.readValue(callbackParser, (Class<Object>) responseClass);

And I set responseClass in this way :

    public void registerUser(HashMap<String, String> parameters) {
        try {
            IMAPICaller caller = new IMAPICaller(this);
            HashMap<String, Object> params = new HashMap<String, Object>();
            params.put("path", "users/register");
            params.put("method", "POST");
            params.put("parameters", parameters);
            params.put("class", User.class);
            params.put("code", ConnectionActivity.REGISTER_USER);
            caller.execute(params);
        }
        catch (NullPointerException NPE) {
            NPE.printStackTrace();
        }
    }

    private class IMAPICaller extends AsyncTask<HashMap<String, Object>, Integer, Object> {
        @Override
        protected Object doInBackground(HashMap<String, Object>... args) {
            Object responseClass = (Object) args[0].get("class");
            [...]
            callbackParser = jsonFactory.createJsonParser(APIconnection.getInputStream());
            response = objectMapper.readValue(callbackParser, (Class<Object>) responseClass);
        }
    
        @Override
        protected void onPostExecute(Object responseObject) {
            Log.i(IMAPIManager.TAG, "onPostExecute");
            this.loader.cancel();
                        
            // Send responseObject to UIThread
            if (responseObject != null) {
                Log.i(TAG, "responseObject is not null");
                Message msg = messageHandler.obtainMessage(activityCode);
                Log.i(IMAPIManager.TAG, "code : " + activityCode);
                msg.what = activityCode;
                msg.obj = responseObject;
                messageHandler.sendMessage(msg);
            }
        }
    }


Is it a good way to process an API management ?
Or is there a better or easier way ?

I made it because I would not have to parse the JsonParser inside my UIThread Activity, but I could if it was necessary...
