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

Jackson Annotations not taken into account #3198

Closed
aaron-sr opened this issue Jul 19, 2021 · 5 comments
Closed

Jackson Annotations not taken into account #3198

aaron-sr opened this issue Jul 19, 2021 · 5 comments
Labels
invalid This doesn't seem right

Comments

@aaron-sr
Copy link

Environment Details

  • Helidon Version: 2.3.2
  • Helidon MP
  • JDK version: 11.0.11
  • OS: Debian Linux

Problem Description

Jackson annotations like @JsonDeserialize are not considered in Resources.

Steps to reproduce

Use following dependency (instead of helidon-media-jsonb)

<dependency>
    <groupId>io.helidon.media</groupId>
    <artifactId>helidon-media-jackson</artifactId>
    <version>2.3.2</version>
</dependency>

Annotate an empty Dto class with a custom deserializer using @JsonDeserialize(using = DtoDeserializer.class).

Test Implementation for DtoSerializer may look like this:

public class DtoDeserializer extends StdDeserializer<Dto> {
	private static final long serialVersionUID = 1L;

	public DtoDeserializer() {
		super(Dto.class);
		throw new RuntimeException();
	}
	
	@Override
	public Dto deserialize(JsonParser parser, DeserializationContext context) {
		throw new RuntimeException();
	}
}

Add a method like this

@POST
@Consumes(MediaType.APPLICATION_JSON)
public void addDto(Dto dto) { ... }

If the custom deserializer is used, an exception must be thrown.

@romain-grecourt
Copy link
Contributor

Not sure if that' the actual problem but io.helidon.media.* is for Helidon SE, however the code snippet you shared is JAXRS based, you need to add a jersey dependency to support Jackson there (i.e org.glassfish.jersey.media:jersey-media-json-jackson)

@aaron-sr
Copy link
Author

@romain-grecourt I added your dependency suggestion instead, but no change. Is there any documentation by Helidon/Oracle for this?

From my point of view, it is not possible to change the default json library to jackson (at least for Resources). Is this correct?

@spericas
Copy link
Member

@aaron-sr It should work using the Jersey dependency. See https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/media.html#json.jackson

If it still doesn't work, please provide a copy of your application log.

@romain-grecourt
Copy link
Contributor

The output of mvn dependency:tree would also be useful ; it would indicate if you are using the helidon-microprofile bundle (e.g. if you created your application with the quickstart-mp archetype).

This dependency groups some of the most common Helidon MicroProfile components and it also configures JSON-B out of the box, it adds the following dependencies:

  • org.glassfish.jersey.media:jersey-media-json-binding
  • jakarta.json.bind:jakarta.json.bind-api
  • org.eclipse:yasson

If you add org.glassfish.jersey.media:jersey-media-json-jackson then it becomes dependent on the class-path ordering.

If you are using helidon-microprofile you should remove the dependency to the helidon-microprofile bundle and instead add direct dependencies to the helidon-microprofile-* components you are using.

Or you can manually exclude the 3 JSON-B related dependencies from the bundle.

@romain-grecourt romain-grecourt added the invalid This doesn't seem right label Aug 5, 2021
@romain-grecourt
Copy link
Contributor

The changes required in the pom.xml would look like this:

<dependency>
    <groupId>io.helidon.microprofile.bundles</groupId>
    <artifactId>helidon-microprofile</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-binding</artifactId>
        </exclusion>
        <exclusion>
            <groupId>jakarta.json.bind</groupId>
            <artifactId>jakarta.json.bind-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.eclipse</groupId>
            <artifactId>yasson</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
</dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
Archived in project
Development

No branches or pull requests

3 participants