The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Converting a Resultset to Contact Objects

Highlighted
Occasional Contributor

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
Highlighted
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
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured