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.

Issues Converting ResultSet to Java Object

Highlighted
Occasional Contributor

Issues Converting ResultSet to Java Object

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. If you want to reply directly, please use email ==> 

 

Thanks,

 

Dave Crout

 

1 REPLY 1
Highlighted
Administrator

Re: Issues Converting ResultSet to Java Object

Hello @Justice_and_Peace. I see that you already posted this same question in our Developer board. They are best suited to help you there with any API questions that you have. We will reach out to that team so you are sure to get a reply. 


Caitlin M.
Community Manager
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.

You're not alone on your email marketing journey. Connect with a Marketing Advisor to see how they can help you develop the right strategy for your business and get the most out of your Constant Contact experience.
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