Title: marshalling private fields

Can Castor XML be easily extended to marshal and unmarshal private properties of Java objects?  For example, map a <text> element to and from:

    private void setText(String text);
    private String getText();

This would be valuable in many cases wherein a class is used primarily for something other than marshalling or unmarshalling.  Often, the public interface of the class should exclude properties that are necessary for marshalling.  The natural and convenient choice is to make those properties private or protected.  People do so routinely when using Java Object Serialization or Hibernate.  It's an unpleasant surprise that Castor can't do likewise.

It's not difficult to call such methods via reflection <http://java.sun.com/j2se/1.3/docs/api/java/lang/reflect/AccessibleObject.html#setAccessible(boolean)>.  Such usage seems appropriate: Castor XML is a 'sophisticated application', as described by AccessibleObject's javadoc.

- John Kristian

Reply via email to