[
https://issues.apache.org/jira/browse/AVRO-3848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17762587#comment-17762587
]
Eduard Schleining commented on AVRO-3848:
-----------------------------------------
Is there a way to use the class specific decoder in a more generic way (at
runtime I do not know which class is being decoded)?
From: Andrei Leib (Jira) <[email protected]>
Date: Thursday, 7. September 2023 at 03:07
To: Schleining, Eduard <[email protected]>
Subject: [jira] [Comment Edited] (AVRO-3848) MessageDeserializer uses wrong
type for map fields
This email originated from outside of CGM. Please do not click links or open
attachments unless you know the sender and know the content is safe.
[
https://deu01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fissues.apache.org%2Fjira%2Fbrowse%2FAVRO-3848%3Fpage%3Dcom.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel%26focusedCommentId%3D17762519%23comment-17762519&data=05%7C01%7C%7C04d07de19476454dea4708dbaf3ec42e%7C69602cf4a76e4265955f03c329c50608%7C0%7C0%7C638296456330250990%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H5Z3QAUqpYq1ObT1trwws9G63PE72J1dav1plta2nUo%3D&reserved=0<https://issues.apache.org/jira/browse/AVRO-3848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17762519#comment-17762519>
]
Andrei Leib edited comment on AVRO-3848 at 9/7/23 1:06 AM:
-----------------------------------------------------------
The Avro compiler supports *stringType* property by inserting Java-specific
annotation "avro.java.string": "String" for all string types
In effect this makes the reader schema different from the writer schema.
Passing the schema without the *avro.java.string* to the decoder is asking Avro
to use default type for string which is *Utf8*
I modified your example as follows and it passed:
{code:java}
private RecordWithMapField deserialize(byte[] serialized) {
try {
return RecordWithMapField.getDecoder().decode(serialized);
} catch (IOException e) {
throw new RuntimeException(e);
}
}{code}
The reader schema is now coming from the compiled class.
was (Author: JIRAUSER296032):
The Avro compiler supports *stringType* property by inserting Java-specific
annotation "avro.java.string": "String" for all string types
In effect this makes the reader schema different from the writer schema.
Passing the schema without the *avro.java.string* to the decoder is asking Avro
to use default type for string which is *Utf8*
I modified your example as follows and it passed:
{code:java}
private RecordWithMapField deserialize(byte[] serialized) {
MessageDecoder<RecordWithMapField> decoder;
try {
Schema schema = RecordWithMapField.getClassSchema();
decoder = new
BinaryMessageDecoder<>(SpecificData.getForClass(RecordWithMapField.class),
schema);
return decoder.decode(serialized);
} catch (IOException e) {
throw new RuntimeException(e);
}
} {code}
The reader schema is now coming from the compiled class.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
> MessageDeserializer uses wrong type for map fields
> --------------------------------------------------
>
> Key: AVRO-3848
> URL: https://issues.apache.org/jira/browse/AVRO-3848
> Project: Apache Avro
> Issue Type: Bug
> Reporter: Eduard Schleining
> Priority: Major
>
> When using the avro-maven-plugin to generate classes with map fields, the
> MessageDecoder will disregard the "stringType" setting and always provide a
> map with entries of type UTF8 instead of String.
> You can see the behavior in the unit test here:
> [https://github.com/eschleining/avroMapDeserialization]
> Expected Behavior:
> The org.apache.avro.message.MessageDecoder should use keys and values of type
> String for classes with fields of type Map<String,String>.
> Actual Behavior:
> The org.apache.avro.message.MessageDecoder puts Map<Utf8,Utf8> into fields
> that are generated as Map<String,String>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)