swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Swagger 2.0 + Jackson: @JsonIdentityInfo doesn't work

Open brucethomax opened this issue 11 years ago • 5 comments

Referencing: http://stackoverflow.com/posts/32692609/edit

We are attempting to have Swagger 2.0. Basically, it's great except it is ignoring the @JsonIdentityInfo and @JsonIdentityReference annotations.

public class Source {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JsonIdentityReference(alwaysAsId=true)
    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name")
    @JsonProperty("sourceDefinitionName")
    private SourceDefinition sourceDefinition;

    ... getters and setters
}

Resulting in the Swagger schema output:

{
     "id": 0,
     "sourceDefinitionName": {
          "configuration": {},
          "driver": "string",
          "id": "string",
          "name": "string",
          "sourceType": "QUERY",
          "title": "string"
     }
}

You can see that it indeed reads the @JsonProperty annotation renaming the "sourceDefinition" to "sourceDefinitionName" but the value should just be a string.

Does anyone have any insight into this sort of problem with this integration?

brucethomax avatar Sep 21 '15 11:09 brucethomax

JsonIdentityReference still doesn't work, using spring fox 2.6.1 version

hanymorcos avatar Aug 10 '17 17:08 hanymorcos

Same for me, I have cyclic dependencies, so I have to use @JsonIdentityInfo. I get a stackoverflow

Romain-P avatar Aug 16 '17 13:08 Romain-P

I'm using JSON Property. That's working for me through swagger. I'm tweaking jhiptser generated code.

hanymorcos avatar Aug 16 '17 13:08 hanymorcos

Still doesn't work. Spring Fox 3.0.0-SNAPSHOT and Swagger Maven Plugin 2.4.0.

desiderati avatar Feb 20 '20 23:02 desiderati

Same issue here :disappointed:

muety avatar Nov 25 '20 13:11 muety