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.

Problem marshalling API response using RestEasy

Highlighted
New Member

Problem marshalling API response using RestEasy

 Hi All,


I am trying to use the Constant Contact API from within Java. I am using RestEasy in combination with JAXB. I am able to send the request using ProxyFactory and I am trying to extract my JAXB Object by using content.getJAXBObject(ContactList.class);

My ContactList class is a JAXB annotated class, namespace is properly set. It has a bunch of elements and one attribute.When I try to access

my ContactList instance only the attribute is properly populated, all elements are still null. Any ideas why this seems to only partially unmarshall?



Here's my ContactList class:

@XmlRootElement(name = "ContactList", namespace = "{namespace}")

@XmlAccessorType(XmlAccessType.PROPERTY)

public class ContactList {



   @XmlAttribute

   public String id;

   .....

   @XmlElement  (name="Name")

   public String name;

   ......





}



Here's the Service that I am calling using ProxyFactory

public interface ContactListService {



  @GET

  @Path("lists/{id}")

  @Produces("application/atom+xml")

  public Entry getListById(@PathParam("id") String id);





....

}



and here's the call to the proxy:



ContactListService  client = ProxyFactory.create(ContactListService

.class, API_BASE + contactListResource, clientExecutor);

Content content = client.getListById("2").getContent();

ContactList list = content.getJAXBObject(ContactList.class);



--> now list.id is properly populated but list.name=null



The returned XML looks like this:







<?xml version="1.0" encoding="UTF-8"?>

<entry xmlns="http://www.w3.org/2005/Atom">

<link href="{some link}" rel="edit"></link>

 <id>{some link}</id>

<title type="text">{some text}</title>

<updated>2011-03-08T21:44:28.155Z</updated>

<author>

<name>{some text}</name>

 </author>

<content type="application/vnd.ctct+xml">16:44:25.992

 <ContactList xmlns="{some namespace}" id="{some text}">

 <OptInDefault>false</OptInDefault>

<Name>test</Name>

<ShortName> test</ShortName>

</ContactList>

</content>

<source>

<id>{some text}</id>

<title type="text">{some text}</title>

<link href="lists"></link>



<link href="lists" rel="self"></link>

<author>

<name>{some text}</name>

</author>

<updated>2011-03-08T21:44:28.155Z</updated>

</source>

</entry>


 


Any help greatly appreciated!

2 REPLIES 2
Highlighted
Employee

Re: Problem marshalling API response using RestEasy

I spoke with David Berard on our AppConnect team who mentioned that you had resolved this issue on your own. If you are still running into any problems please let us know. With that being said, if you did want to post the solution you came up with so that other people can benefit from it as well, that would be much appreciated. Thanks!

David J

Highlighted
New Member

I was able to solve my issue

I was able to solve my issue by using @javax.xml.bind.annotation.XmlSchema(namespace = "http://ws.constantcontact.com/ns/1.0/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)  in my package-info.java file. 

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