I am getting
MessageBodyWriter not found for media type=application/json, type=class java.util.HashMap$Values, genericType=java.util.Collection
from a web service with Glassfish 4.1. Everything I see says to have the jackson or other library in the classpath so that the types can be converted. With Glassfish, I have:
~/apps/glassfish-4.1/glassfish/domains/domain1/logs$ find ../../../../ | grep jackson
../../../../glassfish/modules/jackson-core.jar
../../../../glassfish/modules/jackson-annotations.jar
../../../../glassfish/modules/jackson-databind.jar
../../../../glassfish/modules/jackson-jaxrs-json-provider.jar
../../../../glassfish/modules/jackson-jaxrs-base.jar
../../../../glassfish/modules/jersey-media-json-jackson.jar
Entity Classes:
public class Actor extends AbstractBaseEntity{
public Actor(String id, String name) {
super(id, name);
}
}
public class AbstractBaseEntity {
String identifier;
String name;
public AbstractBaseEntity(String id, String name){
this.identifier = id;
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public String getName() {
return name;
}
}
Service class:
@Path("actors")
public class MockActorService {
private static final int DEFAULT_COUNT = 5;
HashMap<String, Actor> items;
public MockActorService() throws WFlowServiceException {
this(MockActorService.DEFAULT_COUNT);
}
public MockActorService(int actors) throws WFlowServiceException {
items = new HashMap<>();
for (int i = 0; i < actors; i++) {
Actor a = new Actor("ID:" + i, "Actor Name " + i);
items.put(a.getIdentifier(), a);
}
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAll() throws WFlowServiceException {
GenericEntity< Collection< Actor > > entity;
Collection<Actor> vals = items.values();
entity = new GenericEntity<Collection<Actor>>(vals){};
return Response.ok(entity).build();
}
}
Why am I still getting this error?