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

Handling conversion of JSON with standard Avro encoding #749

Merged
merged 2 commits into from
Mar 22, 2017

Conversation

rprzystasz
Copy link
Contributor

@rprzystasz rprzystasz commented Mar 21, 2017

Added avro/json payload content-type and applied standard JSON->AVRO conversion mechanism for messages with this type. (based on https://avro.apache.org/docs/1.8.1/spec.html#json_encoding)

This addresses the issue with custom JSON converter (allegro/json-avro-converter#14), where more complex Union types could not be properly matched, since plain JSON does not carry type information.

For given schema:

{
    "namespace": "pl.allegro",
    "type": "record",
    "name": "User",
    "fields": [
        {
              "name": "__metadata",
              "type": ["null", {"type": "map", "values": "string"}],
              "default": null
        },
        {"name": "name", "type": "string"},
        {"name": "age",  "type": "int"},
        {"name": "favoriteColor", "type": ["null", "string"]}
    ]
}

proper avro/json formatted message is:

{"__metadata":null,"name":"Bob","age":30,"favoriteColor":{"string":"black"}}

NOTE: when namespace is defined, for custom defined types (records, etc. but not primitives) it must be prepended to type discriminator { "<namespace>.<type name>": <value> }

compared to standard application/json:

{"name":"Bob","age":30,"favoriteColor":"black"}

@adamdubiel adamdubiel added this to the 0.11.3 milestone Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants