Partial fix for #8640tags/8.1.0.alpha1
@@ -134,13 +134,18 @@ public class BeanPropertySet<T> implements PropertySet<T> { | |||
@Override | |||
public Optional<Setter<T, V>> getSetter() { | |||
Method setter = descriptor.getWriteMethod(); | |||
if (setter == null) { | |||
if (descriptor.getWriteMethod() == null) { | |||
return Optional.empty(); | |||
} | |||
return Optional.of( | |||
(bean, value) -> invokeWrapExceptions(setter, bean, value)); | |||
Setter<T, V> setter = (bean, value) -> { | |||
// Do not "optimize" this getter call, | |||
// if its done outside the code block, that will produce | |||
// NotSerializableException because of some lambda compilation magic | |||
Method innerSetter = descriptor.getWriteMethod(); | |||
invokeWrapExceptions(innerSetter, bean, value); | |||
}; | |||
return Optional.of(setter); | |||
} | |||
@SuppressWarnings("unchecked") |
@@ -3,6 +3,7 @@ package com.vaadin.data; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertSame; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
import java.util.Set; | |||
@@ -32,7 +33,7 @@ public class BeanBinderTest | |||
private TextField number = new TextField(); | |||
} | |||
private class TestBean { | |||
private static class TestBean implements Serializable{ | |||
private Set<TestEnum> enums; | |||
private int number; | |||
@@ -53,7 +54,7 @@ public class BeanBinderTest | |||
} | |||
} | |||
public class RequiredConstraints { | |||
public static class RequiredConstraints implements Serializable{ | |||
@NotNull | |||
@Max(10) | |||
private String firstname; | |||
@@ -107,6 +108,7 @@ public class BeanBinderTest | |||
// Should correctly bind the enum field without throwing | |||
otherBinder.bindInstanceFields(testClass); | |||
testSerialization(otherBinder); | |||
} | |||
@Test | |||
@@ -122,6 +124,7 @@ public class BeanBinderTest | |||
otherBinder.setBean(bean); | |||
testClass.number.setValue("50"); | |||
assertEquals(50, bean.number); | |||
testSerialization(otherBinder); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@@ -304,6 +307,7 @@ public class BeanBinderTest | |||
binder.setBean(bean); | |||
Assert.assertTrue(field.isRequiredIndicatorVisible()); | |||
testSerialization(binder); | |||
} | |||
@Test | |||
@@ -317,6 +321,7 @@ public class BeanBinderTest | |||
binder.setBean(bean); | |||
Assert.assertTrue(field.isRequiredIndicatorVisible()); | |||
testSerialization(binder); | |||
} | |||
@Test | |||
@@ -330,6 +335,7 @@ public class BeanBinderTest | |||
binder.setBean(bean); | |||
Assert.assertTrue(field.isRequiredIndicatorVisible()); | |||
testSerialization(binder); | |||
} | |||
private void assertInvalid(HasValue<?> field, String message) { |
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
import java.util.concurrent.atomic.AtomicBoolean; | |||
@@ -43,7 +44,7 @@ import com.vaadin.ui.TextField; | |||
public class BinderConverterValidatorTest | |||
extends BinderTestBase<Binder<Person>, Person> { | |||
private static class StatusBean { | |||
private static class StatusBean implements Serializable { | |||
private String status; | |||
public String getStatus() { |
@@ -34,7 +34,7 @@ import com.vaadin.ui.CheckBoxGroup; | |||
public class BinderMultiSelectTest | |||
extends BinderTestBase<Binder<BeanWithEnums>, BeanWithEnums> { | |||
public class TestEnumSetToStringConverter | |||
public static class TestEnumSetToStringConverter | |||
implements Converter<Set<TestEnum>, String> { | |||
@Override | |||
public Result<String> convertToModel(Set<TestEnum> value, |
@@ -15,8 +15,12 @@ | |||
*/ | |||
package com.vaadin.data; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.ObjectOutputStream; | |||
import java.io.Serializable; | |||
import java.util.Locale; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import com.vaadin.ui.TextField; | |||
@@ -28,7 +32,7 @@ import com.vaadin.ui.TextField; | |||
* | |||
* @since 8.0 | |||
*/ | |||
public abstract class BinderTestBase<BINDER extends Binder<ITEM>, ITEM> { | |||
public abstract class BinderTestBase<BINDER extends Binder<ITEM>, ITEM> implements Serializable { | |||
protected static final String NEGATIVE_ERROR_MESSAGE = "Value must be non-negative"; | |||
@@ -50,6 +54,14 @@ public abstract class BinderTestBase<BINDER extends Binder<ITEM>, ITEM> { | |||
protected Validator<Integer> notNegative = Validator.from(x -> x >= 0, | |||
NEGATIVE_ERROR_MESSAGE); | |||
public static void testSerialization(Object toSerialize) { | |||
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream())) { | |||
objectOutputStream.writeObject(toSerialize); | |||
} catch (Exception e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Before | |||
public void setUpBase() { | |||
nameField = new TextField(); | |||
@@ -57,4 +69,9 @@ public abstract class BinderTestBase<BINDER extends Binder<ITEM>, ITEM> { | |||
ageField = new TextField(); | |||
ageField.setLocale(Locale.US); | |||
} | |||
@After | |||
public void testBinderSerialization() { | |||
testSerialization(binder); | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.vaadin.tests.data.bean; | |||
import java.io.Serializable; | |||
import java.util.Calendar; | |||
import javax.validation.Valid; | |||
@@ -11,7 +12,7 @@ import javax.validation.constraints.Past; | |||
import javax.validation.constraints.Pattern; | |||
import javax.validation.constraints.Size; | |||
public class BeanToValidate { | |||
public class BeanToValidate implements Serializable { | |||
@NotNull | |||
@Size(min = 3, max = 16) |
@@ -15,10 +15,11 @@ | |||
*/ | |||
package com.vaadin.tests.data.bean; | |||
import java.io.Serializable; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
public class BeanWithEnums { | |||
public class BeanWithEnums implements Serializable{ | |||
private Set<TestEnum> enums = new HashSet<>(); | |||
public Set<TestEnum> getEnums() { |
@@ -1,9 +1,10 @@ | |||
package com.vaadin.tests.data.bean; | |||
import java.io.Serializable; | |||
import java.math.BigDecimal; | |||
import java.time.LocalDate; | |||
public class Person { | |||
public class Person implements Serializable { | |||
private String firstName; | |||
private String lastName; | |||
private String email; |