Interface handling in REST and JAXB

It is a very common scenario when you are writing a class implementing and interface and your parameters to the classes are interfaces.


public interface Person {}

public class Employee implements Person {}

public class MyEmployeeResources {
public void putEmployee(Person person) {...}

In the above example you will get an error with Jersey or RESTEasy as they both don't know the implementation of Person are JAXB class, hence they don;t have the context of JAXB.

Really cool alternative to this was to use @XMLSeeAlso annotation. something like below

public interface Person {}

This way JAXB creates the JAXBContext of Person, because it knows that it can be unmarshal with Employee or Student class.

Similarly @XMLSeeAlso can be used with JAX-WS.


Post a Comment