{"id":16284989,"url":"https://github.com/goodforgod/avro-json-optional-decoder","last_synced_at":"2025-04-09T00:35:13.877Z","repository":{"id":45942980,"uuid":"306135677","full_name":"GoodforGod/avro-json-optional-decoder","owner":"GoodforGod","description":"⚙️ Java AVRO Decoder with JSON optional/default field support.","archived":false,"fork":false,"pushed_at":"2021-11-25T20:39:11.000Z","size":189,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T07:01:48.219Z","etag":null,"topics":["avro","avro-decoder","avro-default","avro-optional","avro-schema","default","default-values","field","java","optional"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodforGod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-21T20:07:52.000Z","updated_at":"2023-02-26T09:26:48.000Z","dependencies_parsed_at":"2022-09-24T18:34:28.419Z","dependency_job_id":null,"html_url":"https://github.com/GoodforGod/avro-json-optional-decoder","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Favro-json-optional-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Favro-json-optional-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Favro-json-optional-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Favro-json-optional-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodforGod","download_url":"https://codeload.github.com/GoodforGod/avro-json-optional-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247950885,"owners_count":21023605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avro","avro-decoder","avro-default","avro-optional","avro-schema","default","default-values","field","java","optional"],"created_at":"2024-10-10T19:21:49.609Z","updated_at":"2025-04-09T00:35:13.855Z","avatar_url":"https://github.com/GoodforGod.png","language":"Java","readme":"# Avro Json Optional Decoder\n\n![Java CI](https://github.com/GoodforGod/avro-json-optional-decoder/workflows/Java%20CI/badge.svg)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_avro-json-optional-decoder\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=GoodforGod_avro-json-optional-decoder)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_avro-json-optional-decoder\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_avro-json-optional-decoder)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_avro-json-optional-decoder\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_avro-json-optional-decoder)\n\nAvro Decoder with support optional fields in JSON.\n[Based on Celos fork.](https://github.com/Celos/avro-json-decoder)\n\n## Dependency\n\n**Gradle**\n```groovy\ndependencies {\n    implementation 'com.github.goodforgod:avro-json-optional-decoder:1.1.6'\n}\n```\n\n**Maven**\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.goodforgod\u003c/groupId\u003e\n    \u003cartifactId\u003eavro-json-optional-decoder\u003c/artifactId\u003e\n    \u003cversion\u003e1.1.6\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Compatibility\n\nLibrary is Java 1.8 compatible.\n\nLibrary is compatible with different Apache Avro versions. Please use compatible library version for your Apache Avro version.\n\n| [Apache Avro](https://mvnrepository.com/artifact/org.apache.avro/avro-compiler) Version | [Library](https://mvnrepository.com/artifact/com.github.goodforgod/avro-json-optional-decoder) Version |\n| ---- | ---- |\n| [1.9.2](https://mvnrepository.com/artifact/org.apache.avro/avro-compiler/1.9.2) | [1.1.6](https://mvnrepository.com/artifact/com.github.goodforgod/avro-json-optional-decoder/1.1.4) |\n| [1.8.2](https://mvnrepository.com/artifact/org.apache.avro/avro-compiler/1.8.2) | [1.0.1](https://mvnrepository.com/artifact/com.github.goodforgod/avro-json-optional-decoder/1.0.1) |\n\n\n## Optional Field Problem\n\nFor given AVRO Schema.\n```json\n{\n  \"type\" : \"record\",\n  \"name\" : \"Person\",\n  \"fields\" : [ {\n    \"name\" : \"username\",\n    \"type\" : \"string\"\n  }, {\n    \"name\" : \"name\",\n    \"type\" : [ \"null\", \"string\" ]\n  } ]\n}\n```\n\nSuch JSON will be treated correctly.\n```json\n{\"username\":\"user1\",\"name\":null}\n```\n\nHowever, such JSON (name field is missing).\n```json\n{\"username\":\"user1\"}\n```\n\nWill fail with:\n```log\norg.apache.avro.AvroTypeException: Expected field name not found: name\n```\n\n## Solution \n\n**JsonOptionalDecoder** provided by library allow correct JSON validation in both cases,\ndecoding JSON that doesn't specify optional values, provided they have defaults.\n\nCheck [guides](https://www.baeldung.com/java-apache-avro#2-deserialization) on how-to-use Avro Decoders.\n\nBe aware JsonOptionalDecoder is not thread-safe.\n\n### Optional Record Problem\n\nFor given AVRO Schema.\n```json\n{\n  \"name\": \"Test\",\n  \"type\": \"record\",\n  \"fields\": [\n    {\n      \"name\": \"required\",\n      \"type\": \"string\"\n    },\n    {\n      \"name\": \"inner\",\n      \"type\": [\n        \"null\",\n        {\n          \"name\": \"inner\",\n          \"type\": \"record\",\n          \"fields\": [\n            {\n              \"name\": \"req\",\n              \"type\": \"string\"\n            }\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\nThis input will be correct:\n```json\n{\"required\":\"u\", \"inner\": {\"req\": \"q\"}}\n```\n\nAs this input will be correct:\n```json\n{\"required\":\"u\"}\n```\n\n#### By Default\n\nIf property *default* is not specified, then missing field will be treated as [avro *null*](https://avro.apache.org/docs/1.9.2/spec.html#schema_primitive) value.\n\n```json\n{\n    \"name\" : \"name\",\n    \"type\" : [ \"null\", \"string\" ]\n}\n```\n\nYou can specify default value as per AVRO specification.\n\nKeep in mind you *mind putting type corresponding to default value first*, due to AVRO incorrect union type validation.\n```json\n{\n    \"name\" : \"name\",\n    \"type\" : [ \"string\", \"null\" ],\n    \"default\": \"bob\"\n}\n```\n\n## How To Use\n\nChange\n```java\nDecoder decoder = DecoderFactory.get().jsonDecoder(SCHEMA, INPUT_STREAM_OR_STRING);\n```\n\nWith\n```java\nDecoder decoder = new JsonOptionalDecoder(SCHEMA, INPUT_STREAM_OR_STRING);\n```\n\n## License\n\nThis project licensed under the MIT - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodforgod%2Favro-json-optional-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodforgod%2Favro-json-optional-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodforgod%2Favro-json-optional-decoder/lists"}