Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3014

logicalType annotation doesnt seem to work when generating java class from schema

Log workAgile BoardRank to TopRank to BottomAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskConvert to sub-taskMoveLinkCloneLabelsUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.0, 1.10.0
    • Fix Version/s: 1.10.2
    • Component/s: java, logical types, tools
    • Labels:
      None

      Description

      I have a simple avro schema as follows:

       {
        "type": "record",
        "name": "OfferUnderwritingDetailsEvent",
        "namespace": "com.ferozed.avro",
        "fields": [
          {
          "name": "offerRequestId",
          "type": "string"
          },
          {
          "name": "modifiedTimestamp",
          "type": "long",
          "logicalType": "date"
          }
        ]
      }

       

      I use `avro-tools-1.9.0` to generate Java class from it:

      java -jar ~/DevTools/avro-tools-1.9.0.jar compile -dateTimeLogicalTypeImpl joda schema logicalType.avsc . 

       

      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.

          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;
          } 

       

      When using 1.10.0 version of avro-tools, I dont even see the `dateTimeLogicalTypeImpl` option.

      $ 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 
      
      
      

       

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

      I also tried using `logicalType` with an `int` field, and it doesnt work.

        Attachments

        Issue Links

          Activity

          $i18n.getText('security.level.explanation', $currentSelection) Viewable by All Users
          Cancel

            People

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment