Hendré
Hendré

Reputation: 300

No message body writer has been found

I am trying to create a JAX-RS resource that must produce JSON data.

I am running on Apache TomEE 9.0.0-M7 and Jakarta Web Profile 9.1.

Calling getPrincipals on the PrincipalResource class produces the error below.

Why I am getting a java.util.Vector error when the getPrincipal method returns a List?

Please assist.

Mar 05, 2022 10:06:57 PM org.apache.cxf.jaxrs.utils.JAXRSUtils logMessageHandlerProblem SEVERE: No message body writer has been found for class java.util.Vector, ContentType: application/json

Get method

@Path("/principal")
public class PrincipalResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Principal> getPrincipals() {
        AccessControl accessControl = new AccessControl();
        return accessControl.findPrincipals();
    }
}

Principal class

public class Principal {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "principalNumber")
    private long principalNumber;

    @Pattern(regex = Regex.EMAIL, message = "Invlid email address")
    @Column(name = "emailAddress")
    private String emailAddress;

    @Pattern(regex = Regex.FIRST_NAME, message = "Invlid first name")
    @Column(name = "firstName")
    private String firstName;

    @Pattern(regex = Regex.LAST_NAME, message = "Invlid last name")
    @Column(name = "lastName")
    private String lastName;

    @Pattern(regex = Regex.PASSWORD, message = "Invlid password.")
    @Column(name = "principalPassword")
    private String principalPassword;

    @Column(name = "activated")
    private boolean activated;

    @OneToMany(mappedBy = "principal", cascade = CascadeType.ALL)
    @XmlTransient
    private List<PrincipalRole> principalRoles;

    public Principal() {
    }

Maven

        <dependencies>
                        <dependency>
                                        <groupId>jakarta.platform</groupId>
                                        <artifactId>jakarta.jakartaee-web-api</artifactId>
                                        <version>9.1.0</version>
                                        <scope>provided</scope>
                        </dependency>
                        <dependency>
                                        <groupId>za.co.ezimax</groupId>
                                        <artifactId>common</artifactId>
                                        <version>0.0.1</version>
                        </dependency>                               
        </dependencies>

Upvotes: 0

Views: 902

Answers (1)

Carlo Pellegrini
Carlo Pellegrini

Reputation: 5686

The object (Vector) you are returning is not serializable by the default JAXRS implementation. You need to provide a serializable DTO as the return value.

Upvotes: 1

Related Questions