cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a Resultset to Contact Objects

Converting a Resultset to Contact Objects

Hi,

 

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

 

Thanks,

 

Dave Crout

 

1 REPLY 1
Moderator

Re: Converting a Resultset to Contact Objects

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.


Regards,
Jimmy D.
Tier II API Support Engineer