POJOUtils { public static List<FieldValueSetter> getSetters( Class<?> clazz, Schema schema, FieldValueTypeSupplier fieldValueTypeSupplier, TypeConversionsFactory typeConversionsFactory) { return CACHED_SETTERS.computeIfAbsent( ClassWithSchema.create(clazz, schema), c -> { List<FieldValueTypeInformation> types = fieldValueTypeSupplier.get(clazz, schema); return types.stream() .map(t -> createSetter(t, typeConversionsFactory)) .collect(Collectors.toList()); }); }  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 testGeneratedSimpleSetters() { SimplePOJO simplePojo = new SimplePOJO(); List<FieldValueSetter> setters = POJOUtils.getSetters( SimplePOJO.class, SIMPLE_POJO_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory()); assertEquals(12, setters.size()); setters.get(0).set(simplePojo, "field1"); setters.get(1).set(simplePojo, (byte) 41); setters.get(2).set(simplePojo, (short) 42); setters.get(3).set(simplePojo, (int) 43); setters.get(4).set(simplePojo, (long) 44); setters.get(5).set(simplePojo, true); setters.get(6).set(simplePojo, DATE.toInstant()); setters.get(7).set(simplePojo, INSTANT); setters.get(8).set(simplePojo, BYTE_ARRAY); setters.get(9).set(simplePojo, BYTE_BUFFER.array()); setters.get(10).set(simplePojo, new BigDecimal(42)); setters.get(11).set(simplePojo, "stringBuilder"); assertEquals("field1", simplePojo.str); assertEquals((byte) 41, simplePojo.aByte); assertEquals((short) 42, simplePojo.aShort); assertEquals((int) 43, simplePojo.anInt); assertEquals((long) 44, simplePojo.aLong); assertTrue(simplePojo.aBoolean); assertEquals(DATE, simplePojo.dateTime); assertEquals(INSTANT, simplePojo.instant); assertArrayEquals("Unexpected bytes", BYTE_ARRAY, simplePojo.bytes); assertEquals(BYTE_BUFFER, simplePojo.byteBuffer); assertEquals(new BigDecimal(42), simplePojo.bigDecimal); assertEquals("stringBuilder", simplePojo.stringBuilder.toString()); }
@Test public void testGeneratedSimpleBoxedSetters() { POJOWithBoxedFields pojo = new POJOWithBoxedFields(); List<FieldValueSetter> setters = POJOUtils.getSetters( POJOWithBoxedFields.class, POJO_WITH_BOXED_FIELDS_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory()); setters.get(0).set(pojo, (byte) 41); setters.get(1).set(pojo, (short) 42); setters.get(2).set(pojo, (int) 43); setters.get(3).set(pojo, (long) 44); setters.get(4).set(pojo, true); assertEquals((byte) 41, pojo.aByte.byteValue()); assertEquals((short) 42, pojo.aShort.shortValue()); assertEquals((int) 43, pojo.anInt.intValue()); assertEquals((long) 44, pojo.aLong.longValue()); assertTrue(pojo.aBoolean.booleanValue()); }
@Test public void testGeneratedByteBufferSetters() { POJOWithByteArray pojo = new POJOWithByteArray(); List<FieldValueSetter> setters = POJOUtils.getSetters( POJOWithByteArray.class, POJO_WITH_BYTE_ARRAY_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory()); setters.get(0).set(pojo, BYTE_ARRAY); setters.get(1).set(pojo, BYTE_BUFFER.array()); assertArrayEquals("not equal", BYTE_ARRAY, pojo.bytes1); assertEquals(BYTE_BUFFER, pojo.bytes2); }