SpringBeanModelConverter extends AbstractModelConverter<SpringBean, T> { @Override public SpringBean convert(String id, T model) { SpringBean converted = super.convert(model); ReflectionUtils.doWithMethods(model.getClass(), method -> { try { Object object = ReflectionUtils.invokeMethod(method, model); if (object != null) { Property property = new Property(); property.setName(getMethodCall(method.getName())); property.setValue(TypeConversionUtils.convertIfNecessary(object, String.class)); converted.getProperties().add(property); } } catch (Exception e) { log.warn(String.format("Unable to access Spring bean property '%s': %s", method.getName(), e.getMessage())); } }, method -> (method.getName().startsWith("get") || method.getName().startsWith("is")) && !method.getName().equals("getClass") && method.getParameterCount() == 0); converted.setClazz(model.getClass().getName()); converted.setId(id); return converted; } SpringBeanModelConverter(Class<T> sourceModelType); @Override SpringBean convert(String id, T model); @Override String getJavaConfig(SpringBean model);  }
@Test public void testConvert() throws Exception { SpringBeanModelConverter<TestActor> converter = new SpringBeanModelConverter<>(TestActor.class); TestActor actor = new TestActor(); actor.setName("testActor"); SpringBean springBean = converter.convert("actor", actor); Assert.assertEquals(springBean.getId(), "actor"); Assert.assertEquals(springBean.getClazz(), TestActor.class.getName()); Assert.assertEquals(springBean.getProperties().size(), 2L); Assert.assertTrue(springBean.getProperties().stream().anyMatch(property -> property.getName().equals("name") && property.getValue().equals("testActor"))); Assert.assertTrue(springBean.getProperties().stream().anyMatch(property -> property.getName().equals("disabled") && property.getValue().equals("false"))); }