Code, JavaEE

Making An Interface Work With JAXB

I have a Customer class that contains a List of type Product where Product is an interface. I annotated the Customer class with the @XmlRootElement(name=”customer”) annotation and attempted to do a maven clean and maven install. Upon doing the install (which does a compile also) I received an error that JAXB doesn’t work with interfaces. After googling for a solution, I found this stackoverflow post – . After updating my compiler plugin with the compilerArgument tag it worked, it is as follows:


The java interface for Product now includes annotations as follows:

public interface Product {
 public void setId(String id);
 public String getId();

public void setName(String name);
 public String getName();

public void setCost(BigDecimal cost);
 public BigDecimal getCost();


And that’s it… Oh, I also had to add a default no-arg constructor to my Customer class.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s