@Test
  @SuppressWarnings("unchecked")
  public void testOrderPreservation() throws Exception {
    Object[] vals = new Object[constructorArgs.length];
    PositionedByteRange[] encodedGeneric = new PositionedByteRange[constructorArgs.length];
    PositionedByteRange[] encodedSpecialized = new PositionedByteRange[constructorArgs.length];
    Constructor<?> ctor = specialized.encodedClass().getConstructor(Object[].class);
    for (int i = 0; i < vals.length; i++) {
      vals[i] = ctor.newInstance(new Object[] { constructorArgs[i] });
      encodedGeneric[i] =
        new SimplePositionedMutableByteRange(generic.encodedLength(constructorArgs[i]));
      encodedSpecialized[i] =
        new SimplePositionedMutableByteRange(specialized.encodedLength(vals[i]));
    }

    // populate our arrays
    for (int i = 0; i < vals.length; i++) {
      generic.encode(encodedGeneric[i], constructorArgs[i]);
      encodedGeneric[i].setPosition(0);
      specialized.encode(encodedSpecialized[i], vals[i]);
      encodedSpecialized[i].setPosition(0);
      assertArrayEquals(encodedGeneric[i].getBytes(), encodedSpecialized[i].getBytes());
    }

    Arrays.sort(vals);
    Arrays.sort(encodedGeneric);
    Arrays.sort(encodedSpecialized);

    for (int i = 0; i < vals.length; i++) {
      assertEquals("Struct encoder does not preserve sort order at position " + i, vals[i],
        ctor.newInstance(new Object[] { generic.decode(encodedGeneric[i]) }));
      assertEquals("Specialized encoder does not preserve sort order at position " + i, vals[i],
        specialized.decode(encodedSpecialized[i]));
    }
  }
The {@link Struct} equivalent of this type.
hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java