JAXB enumeration with numeric values

后端 未结 3 1792
北恋
北恋 2020-12-14 08:51

I want to restrict input values like this


  
    

        
3条回答
  •  难免孤独
    2020-12-14 09:30

    Yes. You could define the enum yourself instead of having XJC generate it. Then you could instruct XJC to use that enum. You'll need an adapter class, though.

    import acme.MyEnum;
    
    public class MyEnumadapter {
    
        public static MyEnum unmarshal(final String value) {
            if(value == null)
                return null;
            //use some method to identify the enum by the value and return
        }
    
        public static String marshal(final MyEnum value) {
            if (value == null)
                return null;
            //use some method to get the value for the enum
        }
    
    }
    

    Either in a bindings file or embedded in the schema, customize the bindings like this:

    
        
    
    

    MyEnumAdapter is in the default package here, so make sure you use the fully qualified names when doing this yourself.

提交回复
热议问题