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

[jira] [Created] (AVRO-3014) logicalType annotation doesnt seem to work when generating java class from schema

Feroze Daud created AVRO-3014:
---------------------------------

             Summary: logicalType annotation doesnt seem to work when generating java class from schema
                 Key: AVRO-3014
                 URL: https://issues.apache.org/jira/browse/AVRO-3014
             Project: Apache Avro
          Issue Type: Bug
          Components: java, logical types, tools
    Affects Versions: 1.10.0, 1.9.0
            Reporter: Feroze Daud
         Attachments: OfferUnderwritingDetailsEvent.java, logicalType.avsc

I have a simple avro schema as follows:
{noformat}
 {
  "type": "record",
  "name": "OfferUnderwritingDetailsEvent",
  "namespace": "com.ferozed.avro",
  "fields": [
    {
    "name": "offerRequestId",
    "type": "string"
    },
    {
    "name": "modifiedTimestamp",
    "type": "long",
    "logicalType": "date"
    }
  ]
}{noformat}
 

I use `avro-tools-1.9.0` to generate Java class from it:
{noformat}
java -jar ~/DevTools/avro-tools-1.9.0.jar compile -dateTimeLogicalTypeImpl joda schema logicalType.avsc . {noformat}
 

When I look at the generated object, the type of the `setModifiedTimestamp` settor is still `int`. I would have expected `joda.time.Date` or something similar.
{noformat}
    public long getModifiedTimestamp() {
      return modifiedTimestamp;
    }

    public com.ferozed.avro.OfferUnderwritingDetailsEvent.Builder setModifiedTimestamp(long value) {
      validate(fields()[1], value);
      this.modifiedTimestamp = value;
      fieldSetFlags()[1] = true;
      return this;
    } {noformat}
 

When using 1.10.0 version of avro-tools, I dont even see the `dateTimeLogicalTypeImpl` option.
{noformat}
$ java -jar ~/DevTools/avro-tools-1.10.0.jar compile
Usage: [-encoding <outputencoding>] [-string] [-bigDecimal] [-fieldVisibility <visibilityType>] [-templateDir <templateDir>] (schema|protocol) input... outputdir
 input - input files or directories
 outputdir - directory to write generated java
 -encoding <outputencoding> - set the encoding of output file(s)
 -string - use java.lang.String instead of Utf8
 -fieldVisibility [private|public|public_deprecated]- use either and default private
 -bigDecimal - use java.math.BigDecimal for decimal type instead of java.nio.ByteBuffer
 -templateDir - directory with custom Velocity templates 


{noformat}
 

And generating a java class using this schema generates the same object as the 1.9.0 toolset.



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