Git Product home page Git Product logo

Comments (7)

cowtowncoder avatar cowtowncoder commented on June 25, 2024

Would this be possible wrt Avro schema limitations? Would new type be defined as Union, allowing both String and Enum? And which direction is the change? (older schema exception String, new Enum? Or vice versa)

At JsonGenerator (and so AvroGenerator subtype) level Enums are typically written using writeString() anyway (since JSON has no "Enum" type; conversion handled at databind level).
Same for JsonParser/AvroParser.

So I am not 100% sure I yet understand the ask here.

from jackson-dataformats-binary.

jlous avatar jlous commented on June 25, 2024

I am suggesting an option where the generated avro schema for an enum field would simply be String.

This would enable extending the enum in the future, with no change in schema.

from jackson-dataformats-binary.

cowtowncoder avatar cowtowncoder commented on June 25, 2024

@jlous Ah ok. Depending on how implemented it might even be a general MapperFeature; I forget what the division is between model traversal (callbacks generated on serialization settings) and construction of Avro schema.

At this point I probably won't have time to work on this in near term but would be happy to help if anyone else wants to tackle it.

from jackson-dataformats-binary.

MichalFoksa avatar MichalFoksa commented on June 25, 2024

@jlous BTW: If you change in Avro schema enum to string type, serialization and deserialization should work already.

from jackson-dataformats-binary.

MichalFoksa avatar MichalFoksa commented on June 25, 2024

I try to avoid enum in Avro schema. Serializing enum into string is a good idea.

@cowtowncoder
How do you want to control this feature?

I think creating a new AvroGenerator.Feature would be best from API standpoint, but I do not know how to access AvroGenerator.Feature from VisitorFormatWrapperImpl.expectStringFormat(JavaType).

BTW: Here is a draft PR, #496, where this feature is controlled by enableWriteEnumAsString() method:

AvroSchemaGenerator gen = new AvroSchemaGenerator()
    .enableWriteEnumAsString();

from jackson-dataformats-binary.

cowtowncoder avatar cowtowncoder commented on June 25, 2024

Ah. Sorry, saw this comment before adding a note on PR.

Yes, AvroGenerator.Feature would be better but I'd need to think of plumbing.

I think AvroGenerator might be available from SerializerProvider but not sure if that is properly initialized.

from jackson-dataformats-binary.

MichalFoksa avatar MichalFoksa commented on June 25, 2024

Let's continue discussion in PR #496.

from jackson-dataformats-binary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.