Giter Club home page Giter Club logo

avro-json-encoder's Introduction

avro-json-encoder

JSON encoder for AVRO that skips default values. Based on org.apache.avro.io.JsonEncoder from AVRO 1.8.2 and org.apache.avro.io.ExtendedJsonEncoder by zolyfarkas.

This encoder is meant to be used with avro-json-decoder as it is capable of decoding Avro JSON with missing values.

why

Given this schema (in AVRO IDL)

record User {
  string username;
  union {null, string} name = null;
}

a user without a name will be encoded as

{"username":"user1","name":null}

Using this encoder, the output will instead be

{"username":"user1"}

The encoder allows skipping specifying nulls. Use with avro-json-decoder.

how

Replace

JsonEncoder encoder = EncoderFactory.get().jsonEncoder(SCHEMA, OUTPUT_STREAM);

with

ExtendedJsonEncoder encoder = new ExtendedJsonEncoder(SCHEMA, OUTPUT_STREAM);

and pass it to the new ExtendedGenericDatumWriter:

DatumWriter<T> writer = new ExtendedGenericDatumWriter<>(SCHEMA_OR_CLASS);
writer.write(DATA, encoder);

avro-json-encoder's People

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.