Hi!
I use XMLEncoder to encode some files in XML. I want to ignore transient fields like with the plain binary serialization. I use the following piece of code inspired of a tutorial of Sun Microsystems to do so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public static final void forceHandlingOfTransientModifiersForXMLSerialization(Class<?> myClass){ BeanInfo beanInfo = null; try{beanInfo=Introspector.getBeanInfo(myClass);} catch(IntrospectionException ie) {ie.printStackTrace();} if(beanInfo!=null) {PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors(); String fieldName; for(Field field:myClass.getDeclaredFields()) if(Modifier.isTransient(field.getModifiers())) {fieldName=field.getName(); for(PropertyDescriptor propertyDesc:propertyDescriptors) if(propertyDesc.getName().equals(fieldName)) { propertyDesc.setValue("transient",Boolean.TRUE); break; } } } }
|
It works fine except on collections and arrays. For example, if myClass has a field containing a list of image with the transient modifier, it attempts to encode this list

When I use the debug feature of Eclipse, I see that its property descriptor is found and modified. Do you have an idea? Thank you very much for your attention.