users@jaxb.java.net

JAXB Bug [?]: Unknown enum values are unmarhalled as NULLs

From: Andy Malakov <nabblespam_at_malakov.com>
Date: Thu, 7 Feb 2008 13:47:05 -0800 (PST)

It seems that JAXB silently ignores incorrect values of enum types. The
following short program demonstrates this issue. Instead of producing a
parsing mistake like "Cannot parse 'WRONG' as a value of enum type 'Color'"
JAXB unmarshaller simply sets Color to null.


public class JAXBTest {

        @XmlRootElement
        public enum Color {
                Red, Green
        }

        public static void main(String[] args) throws Exception {
                JAXBContext context = JAXBContext.newInstance(Color.class);

                printColor(context, "<color>Red</color>");
                printColor(context, "<color>Green</color>");
                printColor(context, "<color>WRONG</color>");
        }

        private static void printColor(JAXBContext context, String xml)
                        throws JAXBException {
                Unmarshaller um = context.createUnmarshaller();
                Color color = (Color) um.unmarshal(new StringReader(xml));
                System.out.println("Color:" + color);
        }
}

Best Regards,
Andy Malakov
-- 
View this message in context: http://www.nabble.com/JAXB-Bug----%3A-Unknown-enum-values-are-unmarhalled-as-NULLs-tp15344297p15344297.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.