JavaBeanUtils { 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 schemaFromJavaBeanClass(
      Class<?> clazz, FieldValueTypeSupplier fieldValueTypeSupplier); static void validateJavaBean(
      List<FieldValueTypeInformation> getters, List<FieldValueTypeInformation> setters); static List<FieldValueTypeInformation> getFieldTypes(
      Class<?> clazz, Schema schema, FieldValueTypeSupplier fieldValueTypeSupplier); static List<FieldValueGetter> getGetters(
      Class<?> clazz,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static FieldValueGetter createGetter(
      FieldValueTypeInformation typeInformation, TypeConversionsFactory typeConversionsFactory); static List<FieldValueSetter> getSetters(
      Class<?> clazz,
      Schema schema,
      FieldValueTypeSupplier fieldValueTypeSupplier,
      TypeConversionsFactory typeConversionsFactory); static FieldValueSetter createSetter(
      FieldValueTypeInformation typeInformation, 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 final Map<ClassWithSchema, SchemaUserTypeCreator> CACHED_CREATORS; }
@Test public void testGeneratedSimpleSetters() { SimpleBean simpleBean = new SimpleBean(); List<FieldValueSetter> setters = JavaBeanUtils.getSetters( SimpleBean.class, SIMPLE_BEAN_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory()); assertEquals(12, setters.size()); setters.get(0).set(simpleBean, "field1"); setters.get(1).set(simpleBean, (byte) 41); setters.get(2).set(simpleBean, (short) 42); setters.get(3).set(simpleBean, (int) 43); setters.get(4).set(simpleBean, (long) 44); setters.get(5).set(simpleBean, true); setters.get(6).set(simpleBean, DateTime.parse("1979-03-14").toInstant()); setters.get(7).set(simpleBean, DateTime.parse("1979-03-15").toInstant()); setters.get(8).set(simpleBean, "bytes1".getBytes(Charset.defaultCharset())); setters.get(9).set(simpleBean, "bytes2".getBytes(Charset.defaultCharset())); setters.get(10).set(simpleBean, new BigDecimal(42)); setters.get(11).set(simpleBean, "stringBuilder"); assertEquals("field1", simpleBean.getStr()); assertEquals((byte) 41, simpleBean.getaByte()); assertEquals((short) 42, simpleBean.getaShort()); assertEquals((int) 43, simpleBean.getAnInt()); assertEquals((long) 44, simpleBean.getaLong()); assertTrue(simpleBean.isaBoolean()); assertEquals(DateTime.parse("1979-03-14"), simpleBean.getDateTime()); assertEquals(DateTime.parse("1979-03-15").toInstant(), simpleBean.getInstant()); assertArrayEquals( "Unexpected bytes", "bytes1".getBytes(Charset.defaultCharset()), simpleBean.getBytes()); assertEquals( ByteBuffer.wrap("bytes2".getBytes(Charset.defaultCharset())), simpleBean.getByteBuffer()); assertEquals(new BigDecimal(42), simpleBean.getBigDecimal()); assertEquals("stringBuilder", simpleBean.getStringBuilder().toString()); }
@Test public void testGeneratedSimpleBoxedSetters() { BeanWithBoxedFields bean = new BeanWithBoxedFields(); List<FieldValueSetter> setters = JavaBeanUtils.getSetters( BeanWithBoxedFields.class, BEAN_WITH_BOXED_FIELDS_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory()); setters.get(0).set(bean, (byte) 41); setters.get(1).set(bean, (short) 42); setters.get(2).set(bean, (int) 43); setters.get(3).set(bean, (long) 44); setters.get(4).set(bean, true); assertEquals((byte) 41, bean.getaByte().byteValue()); assertEquals((short) 42, bean.getaShort().shortValue()); assertEquals((int) 43, bean.getAnInt().intValue()); assertEquals((long) 44, bean.getaLong().longValue()); assertTrue(bean.getaBoolean().booleanValue()); }
@Test public void testGeneratedByteBufferSetters() { BeanWithByteArray bean = new BeanWithByteArray(); List<FieldValueSetter> setters = JavaBeanUtils.getSetters( BeanWithByteArray.class, BEAN_WITH_BYTE_ARRAY_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory()); setters.get(0).set(bean, "field1".getBytes(Charset.defaultCharset())); setters.get(1).set(bean, "field2".getBytes(Charset.defaultCharset())); assertArrayEquals("not equal", "field1".getBytes(Charset.defaultCharset()), bean.getBytes1()); assertEquals(ByteBuffer.wrap("field2".getBytes(Charset.defaultCharset())), bean.getBytes2()); }