Skip to content

"application/json" provider not binded by default #18

@TryKote

Description

@TryKote

Hi! I'm not sure, that is bug, but by default JacksonJsonProvider.class not registrated in JerseyConfiguration module.

I have situation:
Simple controller:

@Path("/version")
public class VersionController {
    private ApplicationInfo applicationInfo;

    @Inject
    public VersionController(ApplicationInfo applicationInfo) {
        this.applicationInfo = applicationInfo;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public ApplicationInfo getInfo() {
        return applicationInfo;
    }
}

where ApplicationInfo is POJO binded as singleton with @singleton annotation.
I run in IDE, go to /version endpoint — all goes good.
I build package with maven, run it and get error MessageBodyWriter not found for media type=application/json, type=class com.my.package.ApplicationInfo, genericType=class com.my.package.ApplicationInfo.

Other mime-types work fine.

I found solution. It's necessary to manual register JacksonJsonProvider.class in JerseyConfiguration:

        JerseyConfiguration configuration = JerseyConfiguration.builder()
                .addPackage("com.my.package")
                .registerClasses(JacksonJsonProvider.class) // <-- this
                .addPort(1234)
                .build(); 

Correct me if i'm wrong

PS: Thanks a lot for your lib. I have same troubles, you solution made my life easier :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions