mbknor / mbknor-jackson-jsonSchema

Generate JSON Schema with Polymorphism using Jackson annotations
MIT License
235 stars 79 forks source link

Wrong type Exception when changing the order of @JsonSubTypes annotation #106

Open NBau opened 5 years ago

NBau commented 5 years ago

Thank you for the excellent library. Unfortunately I am having some trouble when using a more complex structure. Here is a minimal Example:

Given the following hierarchy:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
        @JsonSubTypes.Type(Line.class),
        @JsonSubTypes.Type(Pt.class) })
public static class Loc  {
}
@JsonSubTypes({
        @JsonSubTypes.Type(Abs.class)
})
public static class Pt extends Loc {
}
public static class Abs extends Pt {
}
public static class Line extends Loc {
    public List<Pt>attr;
}

the generator throws the exception Wrong type - working on [simple type, class com.example.Pt] - got [simple type, class com.example.Abs] when calling 'generator.generateJsonSchema(Loc.class);'

When changing the order of the subtype annotation on Loc to

@JsonSubTypes({
        @JsonSubTypes.Type(Pt.class),
        @JsonSubTypes.Type(Line.class) })

everything works. Unfortunately in our POJOs we cannot modify all of subtype annotations to ensure that there is no backward dependency between them. Is this something that is easy to fix?

mbknor commented 4 years ago

If you create a PR with test-case showing the problem, I'll have a look at trying to fix it

NBau commented 4 years ago

Hi, I noticed that this still has the NeedMoreInfo label. Is there something I can do to clarify the issue?

mbknor commented 4 years ago

Hi, Please see my prev comment.. I want you to create a PR with a test-case showing the problem.

NBau commented 4 years ago

Is my PR #109 not sufficient? I am sorry, I tried to mimic the style of the other tests, but I am not sure how it is supposed to work,

alessiostalla commented 3 years ago

I have the same issue.