Code Monkey home page Code Monkey logo

json-schema-avro's People

Contributors

fge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-schema-avro's Issues

Parsing more complex JSON schemas to Avro

Hi,

I'd like to help improve the json-to-avro converter.
I'm trying to convert the official European Broadcasters metadata ontology (EBUCore, an extension on Dublin Core) to an Avro schema. You can download the XSD schemas here: https://www.ebu.ch/metadata/schemas/EBUCore/ebucore.zip

I've successfully converted the ebucore.xsd file (with it's two dependencies) to a JSON schema by converting them first to a Java classes hierarchy using XJC (JAXB) and then to a JSON schema using com.fasterxml.jackson.module.jsonSchema and this code:

        AnnotationIntrospectorPair introspector = new AnnotationIntrospectorPair( new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()), new JacksonAnnotationIntrospector());

        ObjectMapper objectMapper2 = new ObjectMapper();
        objectMapper2.setAnnotationIntrospector(introspector);

        SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
        objectMapper2.acceptJsonFormatVisitor(objectMapper2.constructType(EbuCoreMainType.class), visitor);
        JsonSchema jsonSchema2 = visitor.finalSchema();
        if (jsonSchemaFile.exists()) {
            jsonSchemaFile.delete();
        }
        ObjectWriter fileSchemaWriter = objectMapper2.writerWithDefaultPrettyPrinter();
        fileSchemaWriter.writeValue(jsonSchemaFile, jsonSchema2);

The resulting file is attached to this issue: ebucore.json

I know the Avro converter is complex and not production ready yet, but I think this might be a good example to try to mature it. This is what I do to convert the schema to Avro:

final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.forJsonRef(JsonRef.emptyRef()), jsonSchema);
        final ValueHolder<SchemaTree> input = ValueHolder.hold("schema", tree);
        AvroWriterProcessor processor = new AvroWriterProcessor();

        ProcessingReport report = new ConsoleProcessingReport(LogLevel.DEBUG);
        Schema jsonSchemaToAvro = processor.process(report, input).getValue();

First thing I had to do to resolve a weird crash was upgrade json-schema-validator in json-schema-avro to version 2.2.6 using this issue as a guide. (I upgraded to Avro v1.7.7 at the same time)

Now the processor kicks off, but dies immediately with: com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: no suitable processor found

Digging around in AvroPredicates.record(), I found that missing "additionalProperties" leads to records not being recognised, which is a bug, I think. So I changed the default in the corresponding code (.asBoolean) to false.

Now the schema gets parsed a fair amount, but crashes on the many $ref occurences in the schema always resulting in in a "com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: no suitable processor found" because no matching predicate was found for eg.

"items" : {
  "type" : "object",
  "$ref" : "urn:jsonschema:com:beligum:blocks:schema:dublincore:jaxb:ElementType"
}

So I'm stuck and could use a helping hand. Does anyone want to have a look at this or guide me in the right direction to make this tool better?

cheers,

b.

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.