1. Thrift
  2. THRIFT-872

Add 'primitive' option to 'Java' code generator


    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.4
    • Fix Version/s: None
    • Component/s: Java - Compiler
    • Labels:
    • Patch Info:
      Patch Available


      I'm attaching a patch that modifies 0.4.0 to add a new 'primitive' compiler option to the Java code generator that will produce a style of code that reduces library dependencies for generated struct and service interfaces. This will make the generated code easier to use in some contexts and more compatible with generated code from prior Thrift releases.

      The 'primitive' option changes generated code in the following ways:

      • Removes dependencies on: BitSet, ByteBuffer, and the third-party org.slf4j.Logger*
      • The 'isset' vector is implemented via boolean[] instead of BitSet
      • The 'Iface' interface for service 'Foo' is moved from an inner class to top-level FooIface.jar (and replaced with dummy Foo.Iface which just extends FooIface)
      • 'binary' fields from the IDL are changed from ByteBuffer back to byte[]

      The patch also includes runtime support library changes:

      • Added writeBinary(byte[]) and readBytes() methods to TProtocol to read and write byte[] primitives
      • Added TBaseHelper.toString(byte[],StringBuilder)

      To use (e.g.): thrift -r --gen java:beans,primitive Foo.thrift

      1) The generated structures and services are more compatible with previous versions (in particular, v 0.2.0), requiring fewer code changes for existing projects upgrading to 0.4.0.
      2) The generated POJO structures and service interfaces have a much lower external dependency "footprint", so may be used more easily in platforms and libraries. For example, the structure .java files and the files may be used within restricted environments like GWT, which don't support java.nio.ByteBuffer, java.util.BitSet, or org.slf4j. (
      3) In some contexts, 'binary' data fields may require fewer lines of code to juggle and serialize slightly faster.

      1. java-primitive-872-v3.patch
        17 kB
        Dave Engberg
      2. java-primitive-872-v2.patch
        17 kB
        Dave Engberg
      3. java-primitive-872.patch
        16 kB
        Dave Engberg



          • Assignee:
            Dave Engberg
          • Votes:
            3 Vote for this issue
            8 Start watching this issue


            • Created: