You might need a custom TypeBindingStrategy and ObjectStringConverter.  This
should work:

public class BooleanTypeBindingStrategy extends TypeBindingStrategy {
        public BindingType bindingType(Class type) {
                if(Boolean.class.isAssignableFrom(type)) {
                        return BindingType.PRIMITIVE;
                } else {
                        return DEFAULT.bindingType(type);
                }
        }
}

public class BooleanObjectStringConverter extends
DefaultObjectStringConverter {
        public String objectToString(Object object, Class type, Context
context) {
                if(object == null) return null;
                else if(Boolean.class.isAssignableFrom(type)) {
                        return object.toString();
                } else {
                        return super.objectToString(object, type, context);
                }
        }

        public Object stringToObject(String string, Class type, Context
context) {
                if(string == null) return null;
                else if(Boolean.class.isAssignableFrom(type)) {
                        return new Boolean(string);
                } else {
                        return super.stringToObject(string, type, context);
                }
        }
}

To use these, you need to register them on the BeanWriter:

BeanWriter bw = new BeanWriter();
bw.getXMLIntrospector()
        .getConfiguration()
        .setTypeBindingStrategy(new BooleanTypeBindingStrategy());
bw.getBindingConfiguration()
        .setObjectStringConverter(new BooleanObjectStringConverter());

If you have a need to implement this for multiple types, then check the wiki
for the CustomerObjectStringConverter class which allows you to register
multiple converters by class (similar to the bean creation chain).  You can
only have one TypeBindingStrategy, so to deal with multiple types you'd have
to keep adding new else ifs in the example above.

Hope that helps,
Jesse



-----Original Message-----
From: J. H. [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 21, 2006 8:17 PM
To: Jakarta Commons Users List
Subject: Boolean getters in Betwixt



Hi all,
    Just started using Betwixt 0.7 and its happily turning my beans into XML
except this annoying scenario where i have a getter of the form

                public Boolean isSomeValue() {....}

where it refuses to believe "someValue" is worthy of being part of the XML.
Of course

                public boolean isSomeValue() {....}

works just fine. Is there anyway i can tell my BeanWriter to count the
former method as a valid getter? (i don't have the ability to change the
getter return type)

thanks all!
    - Jordi


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to