flux
flux

Reputation: 526

Jackson: Can not handle managed/back reference 'defaultReference' with nested DTOs

recently with these two DTO I got this error

MappingJackson2HttpMessageConverter:163 - Failed to evaluate Jackson deserialization for type [simple type, class seml.dto.PoiDto]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': back reference type (java.util.Set) not compatible with managed type (seml.dto.ConceptDto)

As you can see in the code below, I have a Set of ConceptDto objects, that have respectively some sets of broaders/narrowers/relateds ConceptDto object. Surely I was wrong to use @JsonManagedReference/@JsonBackReference but I don't understand how. Can anybody help me with this issue? Thanks to everyone.

PoiDto.java

public class PoiDto extends GenericDto<String>{

    private String id;
    private String uri;
    private String title = "";
    private String description = "";

    @JsonManagedReference
    private Set<ConceptDto> concepts = new HashSet<ConceptDto>();

    @JsonManagedReference
    @JsonBackReference
    private Set<PoiDto> relatedPOIs = new HashSet<PoiDto>();

    private Set<ProductOrServiceDto> relatedProductOrServices = new HashSet<ProductOrServiceDto>();
[...]

ConceptDto.java

public class ConceptDto extends GenericDto<String> {

    private String prefLabelIt;
    private String prefLabelEn;
    private String code;
    private double rating;


    @JsonBackReference
    private Set<ConceptDto> broaders = new HashSet<ConceptDto>();

    @JsonManagedReference
    private Set<ConceptDto> narrowers = new HashSet<ConceptDto>();

    @JsonIgnore
    private Set<ConceptDto> relateds = new HashSet<ConceptDto>();

[...]

Upvotes: 0

Views: 5189

Answers (1)

Veton Kuleta
Veton Kuleta

Reputation: 151

Please try firstly to remove @JsonBackReference and @JsoonManagedReference and add this @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class , property = "id") , i Hope this works with you because i had this same problem and it worked for me :)

Upvotes: 4

Related Questions