|
15 | 15 | */ |
16 | 16 | package com.vaadin.flow.data.binder; |
17 | 17 |
|
| 18 | +import java.beans.PropertyDescriptor; |
18 | 19 | import java.io.ByteArrayInputStream; |
19 | 20 | import java.io.ByteArrayOutputStream; |
20 | 21 | import java.io.ObjectInputStream; |
|
34 | 35 | import org.junit.Test; |
35 | 36 |
|
36 | 37 | import com.vaadin.flow.function.ValueProvider; |
| 38 | +import com.vaadin.flow.internal.BeanUtil; |
37 | 39 | import com.vaadin.flow.tests.data.bean.Address; |
38 | 40 | import com.vaadin.flow.tests.data.bean.Country; |
39 | 41 | import com.vaadin.flow.tests.data.bean.FatherAndSon; |
@@ -72,6 +74,9 @@ public String toString() { |
72 | 74 | } |
73 | 75 | } |
74 | 76 |
|
| 77 | + public record TestRecord(String name, int age) { |
| 78 | + } |
| 79 | + |
75 | 80 | interface Iface3 extends Iface2, Iface { |
76 | 81 | } |
77 | 82 |
|
@@ -217,6 +222,39 @@ public void testSerializeDeserialize_nestedPropertyDefinition() |
217 | 222 | address.getPostalCode(), postalCode); |
218 | 223 | } |
219 | 224 |
|
| 225 | + @Test |
| 226 | + public void testSerializeDeserializeRecord() throws Exception { |
| 227 | + PropertyDefinition<TestRecord, ?> definition = BeanPropertySet |
| 228 | + .get(TestRecord.class).getProperty("name") |
| 229 | + .orElseThrow(AssertionFailedError::new); |
| 230 | + |
| 231 | + PropertyDefinition<TestRecord, ?> deserializedDefinition = ClassesSerializableUtils |
| 232 | + .serializeAndDeserialize(definition); |
| 233 | + |
| 234 | + ValueProvider<TestRecord, ?> getter = deserializedDefinition |
| 235 | + .getGetter(); |
| 236 | + |
| 237 | + TestRecord testRecord = new TestRecord("someone", 42); |
| 238 | + |
| 239 | + String name = (String) getter.apply(testRecord); |
| 240 | + |
| 241 | + Assert.assertEquals("Deserialized definition should be functional", |
| 242 | + "someone", name); |
| 243 | + |
| 244 | + PropertyDescriptor namePropertyDescriptor = BeanUtil |
| 245 | + .getPropertyDescriptor(TestRecord.class, "name"); |
| 246 | + Assert.assertNotNull(namePropertyDescriptor); |
| 247 | + Assert.assertEquals("Property has unexpected name", |
| 248 | + namePropertyDescriptor.getName(), "name"); |
| 249 | + Assert.assertEquals("Property read method has unexpected name", |
| 250 | + namePropertyDescriptor.getReadMethod().getName(), "name"); |
| 251 | + |
| 252 | + Class<?> namePropertyType = BeanUtil.getPropertyType(TestRecord.class, |
| 253 | + "name"); |
| 254 | + Assert.assertEquals("Property type is unexpected", namePropertyType, |
| 255 | + String.class); |
| 256 | + } |
| 257 | + |
220 | 258 | @Test |
221 | 259 | public void nestedPropertyDefinition_samePropertyNameOnMultipleLevels() { |
222 | 260 | PropertyDefinition<FatherAndSon, ?> definition = BeanPropertySet |
|
0 commit comments