ConvertUtils { public static Result<? extends Object> convertToModelValue(AttributeModel am, Object value) { if (value == null) { return Result.ok(null); } boolean grouping = SystemPropertyUtils.useThousandsGroupingInEditMode(); Locale locale = VaadinUtils.getLocale(); if (am.isWeek()) { LocalDateWeekCodeConverter converter = new LocalDateWeekCodeConverter(); return converter.convertToModel((String) value, new ValueContext(locale)); } else if (NumberUtils.isInteger(am.getType())) { if (value instanceof String) { StringToIntegerConverter converter = ConverterFactory.createIntegerConverter(grouping, false); return converter.convertToModel((String) value, new ValueContext(locale)); } else if (value instanceof Double) { return new IntToDoubleConverter().convertToModel((Double) value, new ValueContext(locale)); } } else if (NumberUtils.isLong(am.getType())) { if (value instanceof String) { StringToLongConverter converter = ConverterFactory.createLongConverter(grouping, false); return converter.convertToModel((String) value, new ValueContext(locale)); } else if (value instanceof Double) { return new LongToDoubleConverter().convertToModel((Double) value, new ValueContext(locale)); } } else if (NumberUtils.isDouble(am.getType())) { StringToDoubleConverter converter = ConverterFactory.createDoubleConverter(am.isCurrency(), am.isPercentage(), grouping, am.getPrecision(), SystemPropertyUtils.getDefaultCurrencySymbol()); return converter.convertToModel((String) value, new ValueContext(locale)); } else if (BigDecimal.class.equals(am.getType())) { BigDecimalConverter converter = ConverterFactory.createBigDecimalConverter(am.isCurrency(), am.isPercentage(), grouping, am.getPrecision(), SystemPropertyUtils.getDefaultCurrencySymbol()); return converter.convertToModel((String) value, new ValueContext(locale)); } return Result.ok(value); } private  ConvertUtils(); static Object convertToPresentationValue(AttributeModel am, Object input); static Result<? extends Object> convertToModelValue(AttributeModel am, Object value); @SuppressWarnings("unchecked") static Collection<T> convertCollection(Object value, AttributeModel am);  }
@Test public void testConvertSearchValue() { EntityModel<TestEntity> model = emf.getModel(TestEntity.class); Result<?> result = ConvertUtils.convertToModelValue(model.getAttributeModel("age"), "12"); Object obj = result.getOrThrow(r -> new OCSRuntimeException()); assertTrue(obj instanceof Long); assertEquals(12L, ((Long) obj).longValue()); result = ConvertUtils.convertToModelValue(model.getAttributeModel("discount"), "12,34"); obj = result.getOrThrow(r -> new OCSRuntimeException()); assertTrue(obj instanceof BigDecimal); assertEquals(12.34, ((BigDecimal) obj).doubleValue(), 0.0001); result = ConvertUtils.convertToModelValue(model.getAttributeModel("id"), "17"); obj = result.getOrThrow(r -> new OCSRuntimeException()); assertTrue(obj instanceof Integer); assertEquals(17, ((Integer) obj).intValue()); result = ConvertUtils.convertToModelValue(model.getAttributeModel("birthWeek"), "2015-05"); obj = result.getOrThrow(r -> new OCSRuntimeException()); assertTrue(obj instanceof LocalDate); assertEquals(LocalDate.of(2015, 1, 26), obj); }