Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TryKote opened this issue Sep 4, 2019 · 1 comment
Open

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

TryKote opened this issue Sep 4, 2019 · 1 comment
Assignees

Comments

@TryKote
Copy link

TryKote commented Sep 4, 2019

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 :)

@asafm
Copy link

asafm commented Sep 11, 2019

We didn't necessarily wanted to the change the defaults provided by Jersey it self, as it become more opinionated. Maybe some people like GSON better than Jackson. As long as you can do it in one liner, seems reasonable to me.

@asafm asafm self-assigned this Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants