You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Slava D (Jira)" <ji...@apache.org> on 2020/12/03 15:41:00 UTC
[jira] [Resolved] (AVRO-2996) GenericDatumWriter does not support
writing UUID and BigDecimal in Java
[ https://issues.apache.org/jira/browse/AVRO-2996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Slava D resolved AVRO-2996.
---------------------------
Resolution: Not A Bug
GenericDatumWriter was used instead of SpecificDatumWriter.
There was no real issue.
Perhaps, a more extensive documentation with examples is in place
> GenericDatumWriter does not support writing UUID and BigDecimal in Java
> -----------------------------------------------------------------------
>
> Key: AVRO-2996
> URL: https://issues.apache.org/jira/browse/AVRO-2996
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.10.0
> Environment: Kotlin language v1.3 and v1.4
> using
> {code:java}
> org.apache.avro:avro:1.10.0
> {code}
> Reporter: Slava D
> Priority: Major
>
> GenericDatumWriter writer fails to serialize UUID and BigDecimal fields from DTOs generated from AVRO schemas.
> Serialization code (in Kotlin):
>
> {code:java}
> val writer = GenericDatumWriter<SpecificRecord>(payload.schema)
> val baos = ByteArrayOutputStream()
> val jsonEncoder = EncoderFactory.get().jsonEncoder(payload.schema, baos)
> writer.write(payload, jsonEncoder)
> {code}
>
> Example of Schema:
>
> {code:java}
> {
> "name": "AvroWithUUID",
> "namespace": "com.example.avro",
> "type": "record",
> "fields": [
> { "name": "id", "type": { "type": "string", "logicalType": "uuid" } },
> { "name": "external_id", "type": "string" },
> { "name": "price", "type": {
> "type": "bytes",
> "logicalType": "decimal",
> "precision": 21,
> "scale": 7
> }
> ]
> }
> {code}
> A SpecificRecord class was generated from this code, using conversion to create UUID fields where logicalType is: "uuid" and BigDecimal fields.
> The specific failure occurs at
> GenericDatumWriter.java#writeWithoutConversion at "case STRING:"
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)