POJOUtils { public static List<FieldValueGetter> getGetters( Class<?> clazz, Schema schema, FieldValueTypeSupplier fieldValueTypeSupplier, TypeConversionsFactory typeConversionsFactory) { return CACHED_GETTERS.computeIfAbsent( ClassWithSchema.create(clazz, schema), c -> { List<FieldValueTypeInformation> types = fieldValueTypeSupplier.get(clazz, schema); List<FieldValueGetter> getters = types.stream() .map(t -> createGetter(t, typeConversionsFactory)) .collect(Collectors.toList()); if (getters.size() != schema.getFieldCount()) { throw new RuntimeException( "Was not able to generate getters for schema: " + schema + " class: " + clazz); } return getters; }); }  static Schema schemaFromPojoClass(
      Class<?> clazz, FieldValueTypeSupplier fieldValueTypeSupplier); static List<FieldValueTypeInformation> getFieldTypes(
      Class<?> clazz, Schema schema, FieldValueTypeSupplier fieldValueTypeSupplier); static List<FieldValueGetter> getGetters(
      Class<?> clazz,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static SchemaUserTypeCreator getSetFieldCreator(
      Class<T> clazz,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static SchemaUserTypeCreator getConstructorCreator(
      Class clazz,
      Constructor constructor,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static SchemaUserTypeCreator createConstructorCreator(
      Class<T> clazz,
      Constructor<T> constructor,
      Schema schema,
      List<FieldValueTypeInformation> types,
      TypeConversionsFactory typeConversionsFactory); static SchemaUserTypeCreator getStaticCreator(
      Class clazz,
      Method creator,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static SchemaUserTypeCreator createStaticCreator(
      Class<T> clazz,
      Method creator,
      Schema schema,
      List<FieldValueTypeInformation> types,
      TypeConversionsFactory typeConversionsFactory); static List<FieldValueSetter> getSetters(
      Class<?> clazz,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static final Map<ClassWithSchema, SchemaUserTypeCreator> CACHED_CREATORS; }
@Test public void testGeneratedSimpleGetters() { SimplePOJO simplePojo = new SimplePOJO( "field1", (byte) 41, (short) 42, 43, 44L, true, DATE, INSTANT, BYTE_ARRAY, BYTE_BUFFER, new BigDecimal(42), new StringBuilder("stringBuilder")); List<FieldValueGetter> getters = POJOUtils.getGetters( SimplePOJO.class, SIMPLE_POJO_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory()); assertEquals(12, getters.size()); assertEquals("str", getters.get(0).name()); assertEquals("field1", getters.get(0).get(simplePojo)); assertEquals((byte) 41, getters.get(1).get(simplePojo)); assertEquals((short) 42, getters.get(2).get(simplePojo)); assertEquals((int) 43, getters.get(3).get(simplePojo)); assertEquals((long) 44, getters.get(4).get(simplePojo)); assertTrue((Boolean) getters.get(5).get(simplePojo)); assertEquals(DATE.toInstant(), getters.get(6).get(simplePojo)); assertEquals(INSTANT, getters.get(7).get(simplePojo)); assertArrayEquals("Unexpected bytes", BYTE_ARRAY, (byte[]) getters.get(8).get(simplePojo)); assertArrayEquals( "Unexpected bytes", BYTE_BUFFER.array(), (byte[]) getters.get(9).get(simplePojo)); assertEquals(new BigDecimal(42), getters.get(10).get(simplePojo)); assertEquals("stringBuilder", getters.get(11).get(simplePojo)); }
@Test public void testGeneratedSimpleBoxedGetters() { POJOWithBoxedFields pojo = new POJOWithBoxedFields((byte) 41, (short) 42, 43, 44L, true); List<FieldValueGetter> getters = POJOUtils.getGetters( POJOWithBoxedFields.class, POJO_WITH_BOXED_FIELDS_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory()); assertEquals((byte) 41, getters.get(0).get(pojo)); assertEquals((short) 42, getters.get(1).get(pojo)); assertEquals((int) 43, getters.get(2).get(pojo)); assertEquals((long) 44, getters.get(3).get(pojo)); assertTrue((Boolean) getters.get(4).get(pojo)); }