javajakarta-eeapache-tomee

SEVERE: No message body writer has been found for class java.util.Vector, ContentType: application/xml


I have a minimal JAX-RS application. I am trying to produce an XML response, but instead I get the exception below. The resource should return a List of Country objects, but the exception refers to a Vector. I am running TomEE Web Profile 9.0.0-M7 and Jakarta Web Profile 9.1.

Exception

Mar 04, 2022 12:33:42 PM org.apache.cxf.jaxrs.utils.JAXRSUtils logMessageHandlerProblem
SEVERE: No message body writer has been found for class java.util.Vector, ContentType: application/xml

Application

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/api")
public class RestApplication extends Application {
}

Country Resource

@Path("/country")
public class CountryResource {

    @GET
    @Produces(MediaType.APPLICATION_XML)
    public List<Country> getCountries() {
        return Database.get().findCountries();
    }
}

Country query

public List<Country> findCountries() {
    return em.createQuery("SELECT c FROM Country c ORDER BY c.countryName", Country.class).getResultList();
}

Solution

  • Country needs to be annotated with an XmlRootElement annotation.