[ 
https://issues.apache.org/jira/browse/AVRO-3536?focusedWorklogId=783725&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-783725
 ]

ASF GitHub Bot logged work on AVRO-3536:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Jun/22 06:54
            Start Date: 22/Jun/22 06:54
    Worklog Time Spent: 10m 
      Work Description: im-pratham commented on code in PR #1721:
URL: https://github.com/apache/avro/pull/1721#discussion_r903347990


##########
lang/java/avro/src/test/java/org/apache/avro/specific/TestUnionRecord.java:
##########
@@ -0,0 +1,306 @@
+/**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.avro.specific;
+
+import org.apache.avro.message.BinaryMessageDecoder;
+import org.apache.avro.message.BinaryMessageEncoder;
+import org.apache.avro.message.SchemaStore;
+
+@AvroGenerated
+public class TestUnionRecord extends SpecificRecordBase implements 
SpecificRecord {
+  private static final long serialVersionUID = -3829374192747523457L;
+
+  public static final org.apache.avro.Schema SCHEMA$ = new 
org.apache.avro.Schema.Parser().parse(
+      
"{\"type\":\"record\",\"name\":\"TestUnionRecord\",\"namespace\":\"org.apache.avro.specific\",\"fields\":[{\"name\":\"amount\",\"type\":[\"null\",{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":31,\"scale\":8}],\"default\":null}]}");
+
+  public static org.apache.avro.Schema getClassSchema() {
+    return SCHEMA$;
+  }
+
+  private static final SpecificData MODEL$ = new SpecificData();
+  static {
+    MODEL$.addLogicalTypeConversion(new 
org.apache.avro.Conversions.DecimalConversion());
+  }
+
+  private static final BinaryMessageEncoder<TestUnionRecord> ENCODER = new 
BinaryMessageEncoder<TestUnionRecord>(MODEL$,
+      SCHEMA$);
+
+  private static final BinaryMessageDecoder<TestUnionRecord> DECODER = new 
BinaryMessageDecoder<TestUnionRecord>(MODEL$,
+      SCHEMA$);
+
+  /**
+   * Return the BinaryMessageEncoder instance used by this class.
+   * 
+   * @return the message encoder used by this class
+   */
+  public static BinaryMessageEncoder<TestUnionRecord> getEncoder() {
+    return ENCODER;
+  }
+
+  /**
+   * Return the BinaryMessageDecoder instance used by this class.
+   * 
+   * @return the message decoder used by this class
+   */
+  public static BinaryMessageDecoder<TestUnionRecord> getDecoder() {
+    return DECODER;
+  }
+
+  /**
+   * Create a new BinaryMessageDecoder instance for this class that uses the
+   * specified {@link SchemaStore}.
+   * 
+   * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
+   * @return a BinaryMessageDecoder instance for this class backed by the given
+   *         SchemaStore
+   */
+  public static BinaryMessageDecoder<TestUnionRecord> 
createDecoder(SchemaStore resolver) {
+    return new BinaryMessageDecoder<TestUnionRecord>(MODEL$, SCHEMA$, 
resolver);
+  }
+
+  /**
+   * Serializes this TestUnionRecord to a ByteBuffer.
+   * 
+   * @return a buffer holding the serialized data for this instance
+   * @throws java.io.IOException if this instance could not be serialized
+   */
+  public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
+    return ENCODER.encode(this);
+  }
+
+  /**
+   * Deserializes a TestUnionRecord from a ByteBuffer.
+   * 
+   * @param b a byte buffer holding serialized data for an instance of this 
class
+   * @return a TestUnionRecord instance decoded from the given buffer
+   * @throws java.io.IOException if the given bytes could not be deserialized 
into
+   *                             an instance of this class
+   */
+  public static TestUnionRecord fromByteBuffer(java.nio.ByteBuffer b) throws 
java.io.IOException {
+    return DECODER.decode(b);
+  }
+
+  private java.math.BigDecimal amount;
+
+  /**
+   * Default constructor. Note that this does not initialize fields to their
+   * default values from the schema. If that is desired then one should use
+   * <code>newBuilder()</code>.
+   */
+  public TestUnionRecord() {
+  }
+
+  /**
+   * All-args constructor.
+   * 
+   * @param amount The new value for amount
+   */
+  public TestUnionRecord(java.math.BigDecimal amount) {
+    this.amount = amount;
+  }
+
+  public SpecificData getSpecificData() {

Review Comment:
   This is auto generated avro code. Added @Suppress





Issue Time Tracking
-------------------

    Worklog Id:     (was: 783725)
    Time Spent: 1h  (was: 50m)

> Union type not inheriting type conversions
> ------------------------------------------
>
>                 Key: AVRO-3536
>                 URL: https://issues.apache.org/jira/browse/AVRO-3536
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.11.0
>            Reporter: Prathamesh
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: Test1.avsc, avro-union-issue.zip
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> The attached schema has top-level AVRO Union type. Whenever the client tries 
> to deserialize the message it fails at parsing field - opt_amount, with stack 
> trace - 
> {code:java}
> Caused by: java.lang.ClassCastException: class java.nio.HeapByteBuffer cannot 
> be cast to class java.math.BigDecimal (java.nio.HeapByteBuffer and 
> java.math.BigDecimal are in module java.base of loader 'bootstrap')
> at io.confluent.base.model.Test1.put(Test1.java:115)
> at org.apache.avro.generic.GenericData.setField(GenericData.java:837)
> at 
> org.apache.avro.specific.SpecificDatumReader.readField(SpecificDatumReader.java:139)
> at 
> org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:248)
> at 
> org.apache.avro.specific.SpecificDatumReader.readRecord(SpecificDatumReader.java:123)
> at 
> org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:180)
> at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161)
> at 
> org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:188)
> at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161)
> at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:154)
> at 
> io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer$DeserializationContext.read(AbstractKafkaAvroDeserializer.java:400)
>  {code}
> The sample message you can try is -
> {code:java}
> { "io.confluent.base.model.Test1": { "opt_amount": { "bytes": "10.2" } } } 
> {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to