You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Thorsten Hake (Jira)" <ji...@apache.org> on 2020/01/19 12:44:00 UTC

[jira] [Commented] (AVRO-2641) Generated code results in java.lang.ClassCastException when deserializing

    [ https://issues.apache.org/jira/browse/AVRO-2641?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17018902#comment-17018902 ] 

Thorsten Hake commented on AVRO-2641:
-------------------------------------

This problem seems to relate to the issue I've just created AVRO-2702. For me the deserialization to java.lang.String did not work for a specific schema constellation.

Can you provide an example avro schema that triggers this problem? Maybe this is just a symptom of AVRO-2702. Usually strings in avro are deserialized into java.lang.String if the type property "avro.java.string" is set to String. Thus if the read schema has this property set for all strings that should become java.lang.String, casting in put should not be a problem. I would even argue that calling toString() in the generated code may cover bugs in the deserialization of avro records, as strings should be deserialized to the correct type before calling put on the SpecificRecord.

 

> Generated code results in java.lang.ClassCastException when deserializing
> -------------------------------------------------------------------------
>
>                 Key: AVRO-2641
>                 URL: https://issues.apache.org/jira/browse/AVRO-2641
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.0
>            Reporter: Magne Moss Helleborg
>            Priority: Major
>
> SpecificRecord put() used by datumreader does not account for that String fields can be represented as org.apache.avro.util.Utf8 or other CharSequence which might not be castable to java.lang.String.
> The result is that  when it tries to deserialize Utf8-fields it fails with a ClassCastException.
> Proposed solution: toString() instead of cast for Strings.
>  
> To reproduce error: Serialize schema with String definitions from the .Net Avro library, ex Confluent.Apache.Avro. It will default to UTF-8 for strings, and fail when deserializing the same schema from the JVM.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)