Skip to content

Jackson module scala potentially breaks serialization for swagger Model #454

Closed
@nick-benoit14

Description

@nick-benoit14

Hello, running into a bit of a weird case here. Our project is in scala, but I have reproduced minimally with the code below. When I run the following

`
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new DefaultScalaModule());

    Model model = new ModelImpl();

    Property property = new IntegerProperty();

    Map<String, Property> map = new HashMap<String, Property>();
    map.put("foo", property);
    model.setProperties(map);
    System.out.println(mapper.writeValueAsString(model));

`

I end up with the following exception com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle

When I remove

mapper.registerModule(new DefaultScalaModule());

Things deserialize as I would expect. It could be that I have something misconfigured somewhere, but I am surprised that the inclusion of the DefaultScalaModule makes a difference as ModelImpl is not a scala collection or class. More details on ModelImpl: https://www.javadoc.io/doc/io.swagger/swagger-models/1.5.13/io/swagger/models/ModelImpl.html

Any thoughts?

From my minimal example:
compile "io.dropwizard:dropwizard-jackson:2.0.10" compile "io.swagger:swagger-jersey2-jaxrs:1.5.13" compile "com.fasterxml.jackson.module:jackson-module-scala_2.12:+"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions