users@jaxb.java.net

Boolean type - unmarshalling

From: Vallamshettla, Anand <Anand.Vallamshettla_at_tgslc.org>
Date: Wed, 7 Jun 2006 12:33:38 -0500

Boolean type fields are not parsed properly.

 

Take for example - <BooleanTypeTag> is mapped to Jaxb2 generated
'Boolean' type field.

 

If a document with <BooleanTypeTag>hello</ BooleanTypeTag> is
unmarshalled, Jaxb2 is setting the value to 'false'. Shouldn't the value
of the field be 'null'?

 

Let's say, we unmashall <BooleanTypeTag>turkey</ BooleanTypeTag>, the
value of the field is set to 'true'.

 

In both cases, we would expect Jaxb2 to set the value of the field to
'null' as the type doesn't match.

 

Following is the jaxb code - it looks at the first char only to
determine Boolean value

 

    com.sun.xml.bind.DatatypeConverterImpl

    

    public static boolean _parseBoolean(CharSequence literal) {

        int i=0;

        int len = literal.length();

        char ch;

        do {

            ch = literal.charAt(i++);

        } while(WhiteSpaceProcessor.isWhiteSpace(ch) && i<len);

 

        // if we are strict about errors, check i==len. and report an
error

 

        if( ch=='t' || ch=='1' ) return true;

        if( ch=='f' || ch=='0' ) return false;

        TODO.checkSpec("issue #42");

        return false;

    }

 

called from

 

    com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl

    

                new StringImpl<Boolean>(Boolean.class,

                createXS("boolean")

                ) {

                public Boolean parse(CharSequence text) {

                    return DatatypeConverterImpl._parseBoolean(text);

                }

 

                public String print(Boolean v) {

                    return v.toString();

                }

            }

 

 

1) Is this a bug?

2) Is there a document that describes how unmarshalling will be
done when values doesn't math type?

 

 

Thanks,

Anand