Skip to content

AvroSchema: Does not include base class for records with subclasses #589

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

Closed
raphw opened this issue May 7, 2025 · 5 comments
Closed

AvroSchema: Does not include base class for records with subclasses #589

raphw opened this issue May 7, 2025 · 5 comments
Milestone

Comments

@raphw
Copy link

raphw commented May 7, 2025

I think I encountered an issue in the schema generation of records that are unions:

Given the following example (using Jakarta annotations and the introspector that follows with it):

@XmlType(name = "Super")
@XmlAccessType(FIELD)
@XmlSeeAlso(Sub.class)
class Super { 
    @XmlElement(required = true)
    String foo; // getter, setter
}

@XmlType(name = "Sub")
@XmlAccessType(FIELD)
class Sub extends Super { 
    @XmlElement(required = true)
    String bar; // getter, setter
}

where the class Sub is correctly identified, a value of Super is not allowed in the created union.

To avoid this issue, unionSchemas should also include type, if type is non-abstract.

@cowtowncoder
Copy link
Member

I think a slightly more extensive example would be useful to show how types in question are used (which specific class is schema being generated etc).
For example, Super here has nothing to link it to Sub (@JsonSubTypes would solve that), but not sure that is what is being problem here.

@raphw
Copy link
Author

raphw commented May 8, 2025

In my case, I am using Jakarta annotations and the respective introspector (see edit above). But any introspector would do. The problem is that the introspector is requested to return the subclasses and does so correctly:

List<NamedType> subTypes = getProvider().getAnnotationIntrospector().findSubtypes(bean.getClassInfo());

The base class is no longer considered, what is correct if it is abstract. However, a non-abstract class should be considered.

@cowtowncoder
Copy link
Member

Ah. Good to know the issue.

@MichalFoksa WDYT? Sounds like it could be an easy fix if you agree this is something to fix.

@MichalFoksa
Copy link
Contributor

Hi there,
I could reproduce the problem and I have ugly fix.
Let me refine it somehow.

@cowtowncoder
Copy link
Member

@MichalFoksa sounds good. Depending on whether change is backwards-compatible, can target different branch: if compatible and appears safe, 2.18 (I am thinking of nominating 2.18 as our first ever LTS branch so trying to get safe fixes merged there, get eventually released); if not API compatible or risky, 2.x (for 2.20).

MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 14, 2025
…s is not abstract or interface) into union of types.
MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 14, 2025
…ckson.dataformat.avro.schema.RecordVisitor_schemaCreationTest.Cat"
@cowtowncoder cowtowncoder added 2.19 and removed 2.20 labels May 22, 2025
@cowtowncoder cowtowncoder added this to the 2.19.1 milestone May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants