BeanPropertySet implements PropertySet<T> { @SuppressWarnings("unchecked") public static <T> PropertySet<T> get(Class<? extends T> beanType) { Objects.requireNonNull(beanType, "Bean type cannot be null"); InstanceKey key = new InstanceKey(beanType, false, 0, null); return (PropertySet<T>) INSTANCES.computeIfAbsent(key, ignored -> new BeanPropertySet<>(key)).copy(); } private  BeanPropertySet(InstanceKey<T> instanceKey); private  BeanPropertySet(InstanceKey<T> instanceKey,
            Map<String, PropertyDefinition<T, ?>> definitions); private  BeanPropertySet(InstanceKey<T> instanceKey,
            boolean checkNestedDefinitions,
            PropertyFilterDefinition propertyFilterDefinition); @SuppressWarnings("unchecked") static PropertySet<T> get(Class<? extends T> beanType); @SuppressWarnings("unchecked") static PropertySet<T> get(Class<? extends T> beanType,
            boolean checkNestedDefinitions,
            PropertyFilterDefinition filterDefinition); @Override Stream<PropertyDefinition<T, ?>> getProperties(); @Override Optional<PropertyDefinition<T, ?>> getProperty(String name); Class<T> getBeanType(); @Override String toString();  }
@Test public void testSerializeDeserialize_propertySet() throws Exception { PropertySet<Person> originalPropertySet = BeanPropertySet .get(Person.class); PropertySet<Person> deserializedPropertySet = ClassesSerializableUtils .serializeAndDeserialize(originalPropertySet); comparePropertySet(originalPropertySet, deserializedPropertySet, "Deserialized instance should be the same as the original"); }
@Test public void testSerializeDeserialize_propertySet_cacheCleared() throws Exception { PropertySet<Person> originalPropertySet = BeanPropertySet .get(Person.class); ByteArrayOutputStream bs = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bs); out.writeObject(originalPropertySet); byte[] data = bs.toByteArray(); Field instancesField = BeanPropertySet.class .getDeclaredField("INSTANCES"); instancesField.setAccessible(true); Map<?, ?> instances = (Map<?, ?>) instancesField.get(null); instances.clear(); ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(data)); PropertySet<Person> deserializedPropertySet = (PropertySet<Person>) in .readObject(); comparePropertySet(BeanPropertySet.get(Person.class), deserializedPropertySet, "Deserialized instance should be the same as in the cache"); Assert.assertNotSame( "Deserialized instance should not be the same as the original", originalPropertySet, deserializedPropertySet); }