BeanModelType implements ComplexModelType<T> { @Override public T modelToApplication(Serializable modelValue) { if (modelValue == null) { return null; } if (modelValue instanceof StateNode) { return TemplateModelProxyHandler .createModelProxy((StateNode) modelValue, this); } else if (modelValue instanceof JsonObject) { throw new IllegalArgumentException(String.format( "The stored model value '%s' " + "is a JSON object. It looks like you have receieved a plain " + "JSON from the client side and try to use it as a model. " + "Check your model definition. Client side objects cannot be " + "converted automatically to model bean instances. " + "Most likely you should use JsonValue type for your model property", modelValue)); } else { throw new IllegalArgumentException(String.format( "The stored model value '%s' type '%s' " + "cannot be used as a type for a model property", modelValue, modelValue.getClass().getName())); } } protected  BeanModelType(Class<T> proxyType,
            Map<String, BeanModelTypeProperty> properties,
            boolean allowEmptyProperties); private  BeanModelType(Class<T> javaType, PropertyFilter propertyFilter,
            PathLookup<ModelEncoder<?, ?>> converterLookup,
            PathLookup<ClientUpdateMode> clientUpdateLookup); protected  BeanModelType(Class<T> javaType, PropertyFilter propertyFilter,
            boolean allowEmptyProperties); static boolean isBean(Type type); boolean hasProperty(String propertyName); ModelType getPropertyType(String propertyName); @Override T modelToApplication(Serializable modelValue); Class<T> getProxyType(); @Override StateNode applicationToModel(Object applicationValue,
            PropertyFilter filter); void importProperties(ElementPropertyMap model, Object bean,
            PropertyFilter propertyFilter); ModelType resolveType(String modelPath); @Override @SuppressWarnings("unchecked") BeanModelType<C> cast(Class<C> proxyType); Stream<String> getPropertyNames(); @Override boolean accepts(Type applicationType); @Override Type getJavaType(); @Override JsonValue toJson(); @Override void createInitialValue(StateNode node, String property); void createInitialValues(StateNode node); Map<String, Boolean> getClientUpdateAllowedProperties(
            Set<String> twoWayBindingPaths);  }
@Test public void modelToApplication() { BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false); ElementPropertyMap model = createEmptyModel(); model.setProperty("string", "3"); model.setProperty("intValue", Integer.valueOf(3)); Bean bean = beanType.modelToApplication(model.getNode()); Assert.assertEquals("3", bean.getString()); Assert.assertEquals(3, bean.getIntValue()); Assert.assertNull(bean.getIntObject()); }
@Test public void clientValueToApplication() { BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false); ElementPropertyMap model = createEmptyModel(); model.setProperty("doubleValue", JsonCodec.decodeWithoutTypeInfo(Json.create(3))); model.setProperty("doubleObject", JsonCodec.decodeWithoutTypeInfo(Json.create(3))); model.setProperty("intValue", JsonCodec.decodeWithoutTypeInfo(Json.create(3))); model.setProperty("intObject", JsonCodec.decodeWithoutTypeInfo(Json.create(3))); model.setProperty("booleanValue", JsonCodec.decodeWithoutTypeInfo(Json.create(true))); model.setProperty("booleanObject", JsonCodec.decodeWithoutTypeInfo(Json.create(true))); model.setProperty("string", JsonCodec.decodeWithoutTypeInfo(Json.create("3"))); Bean bean = beanType.modelToApplication(model.getNode()); Assert.assertEquals(3.0, bean.getDoubleValue(), 0); Assert.assertEquals(3.0, bean.getDoubleObject(), 0); Assert.assertEquals(3, bean.getIntValue()); Assert.assertEquals(3, bean.getIntObject().intValue()); Assert.assertEquals(Boolean.TRUE, bean.getBooleanObject()); Assert.assertTrue(bean.isBooleanValue()); Assert.assertEquals("3", bean.getString()); }