Skip to content
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

Avro schema generation: allow override namespace with new @AvroNamespace annotation #310

Closed
fleetwoods opened this issue Jan 13, 2022 · 3 comments
Labels
Milestone

Comments

@fleetwoods
Copy link

I was hoping to override the namespace used in the schemas generated by AvroSchemaGenerator for my POJOs, as opposed to the package name that is used (as it does not make sense to the consumers of my topic, outside of my application).

I cannot workout a means to do this, I tried @JsonRootName(value = "ClassName", namespace = "my.domain") but that is not picked up, is there any other means to achieve this?

Note this is not the same as @JsonAlias, I would like to control the namespace, not the aliases.

Code currently used:

    public static AvroSchema generateSchema(final Class<?> clazz) {
        final AvroSchemaGenerator gen = new AvroSchemaGenerator();
        gen.enableLogicalTypes();
        try {
            MAPPER.acceptJsonFormatVisitor(clazz, gen);
        } catch (JsonMappingException e) {
            throw new IllegalArgumentException("Cannot generate schema for: " + clazz, e);
        }
        return gen.getGeneratedSchema();
    }
@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 13, 2022

As things are, namespace is unfortunately only used with XML backend.
But conceptually I can see how this could be useful for Avro as well.

If anyone has time to try a PR I'd be happy to help, but I do not have time to work on this directly myself.

One small thing about possible implementation: this should be an opt-in feature, for backwards compatibility.
I can help with that aspect if need be.

MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 7, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 7, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 7, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 7, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
@MichalFoksa
Copy link
Contributor

Hi @cowtowncoder

I think I found simple way how to override default Avro namespace value with a new, custom, annotation.

Please , see #324.

MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 8, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
MichalFoksa added a commit to MichalFoksa/jackson-dataformats-binary that referenced this issue May 9, 2022
…ield namespace. Current namespace value is Java package name. This annotation allows to override its name.
@cowtowncoder cowtowncoder changed the title Avro schema generation - Override namespace Avro schema generation: allow override namespace with new @AvroNamespace annotation May 15, 2022
@cowtowncoder cowtowncoder added this to the 2.14.0 milestone May 15, 2022
@cowtowncoder
Copy link
Member

Will be released as part of 2.14.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants