[ 
https://issues.apache.org/jira/browse/AVRO-2996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Slava D updated AVRO-2996:
--------------------------
    Description: 
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:"

 

  was:
GenericDatumWriter writer fails to serialize UUID 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" }
 ]
}
{code}
A SpecificRecord class was generated from this code, using conversion to create 
UUID fields where logicalType is: "uuid"

The specific failure occurs at

GenericDatumWriter.java#writeWithoutConversion at "case STRING:"

 


> GenericDatumWriter does not support writing UUID 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)

Reply via email to