We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Converting a Resultset to Contact Objects


Converting a Resultset to Contact Objects



I am calling the API to return a list of Contacts.I can successfully get the list back, however I am having trouble coverting the elements of the List to a Contact Object in Java. The internal elements of the list are LinkedHashMap.


ResultSet<Contact> rsContact = restTemplate.getForObject("https://api.constantcontact.com/v2/contacts?status=ALL&limit=50&api_key=<API_KEY&access_token="<toke...>", ResultSet.class);


The LinkedHashMap cannot be converted to a Contact object directly, so I tried using an ObjectMapper for the conversion. this threw an exception, indicating there was a field named "field" in the CustomField object that could not be mapped.


ObjectMapper mapper = new ObjectMapper();

List<Contact> pojos = mapper.convertValue(list, new TypeReference<List<Contact>>() { });//[conversion of Linkedhashmap][1]


I then tried to map by calling a method on the Component object. Again, the list elements returned are LinkedHashMaps, not a Contact object.


List<Contact> lstContacts = Component.listFromJSON(strContactJSON, Contact.class);

Contact cccc = lstContacts.get(0);


If you decompose the LinkedHashMap, the Contact data is there, but I just cannot get it mapped to a Contact object.


Any help would be greatly appreciated. Please reply to email ==> david.crout@stfrancisraleigh.org




Dave Crout



Hello Dave,


Something to keep in mind with the resultset is that it contains a list of results and pagination data; you will need to make sure to not convert the result directly because of this. I will email you a more detailed response.

Jimmy D.
Tier II API Support Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page