You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "William Daniels (Jira)" <ji...@apache.org> on 2021/02/11 19:50:00 UTC

[jira] [Commented] (AVRO-2838) Schema in generated Java class is different than the original one

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

William Daniels commented on AVRO-2838:
---------------------------------------

+1 to this issue, we are seeing this with our environment. (left a comment with slightly more detail on [https://github.com/confluentinc/schema-registry/issues/1677] ). You are forced into one of a few options, realistically:

* Your users create all schemas with `avro.java.string` instead of `string`, bad for multi-language support and portability
* You use `CharSequence` for everything, bad due to having to null check everywhere, and charSequence can't be a key in a map
* You force the usage of 'user.latest.version' (see GH issue above details of why that's not advised)
* You introduce custom code during schema registration time to turn `string` into a `avro.java.string` to obscure the issue from the end user, bad due to potential bugs in pattern matching, and the schema the users crafted don't match what actually gets uploaded.. which is very confusing
* You don't use code generation at all and a custom serde implementation (a la Ryan Skraba's approach)
* you wrap the usage of the generated code somehow and obscure the `CharSequence` to the end user, doing your own null checking, and turning it into a string on the api surface. 
* etc

There are probably other problems and various workarounds, but in the end, it seems reasonable to say that the generated schema used should match the schema it was generated from, especially with regards to primitive types, but in general also.

> Schema in generated Java class is different than the original one
> -----------------------------------------------------------------
>
>                 Key: AVRO-2838
>                 URL: https://issues.apache.org/jira/browse/AVRO-2838
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>            Reporter: Lukas Krecan
>            Priority: Major
>         Attachments: AVRO.patch
>
>
> If you generate Java classes from schema, {{SCHEMA$}} variable differs from the original schema. It causes issues like [this|https://github.com/confluentinc/schema-registry/issues/868] and [this|https://github.com/confluentinc/schema-registry/issues/1352] when using Schema registry.
> The issue happens when the schema in the registry is configured externally and then you try to use generated Java class. The schema in the registry does not match the schema in the class and thus the write is refused.
> Technically it's easy to fix (see the attached patch) but I guess there will be some backward compatibility concerns. 
> If it is not acceptable, would it be at least possible to add the {{originalSchema}} context variable so we could solve it using custom template.
> The patch is not final, its purpose is just to convey the idea.



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