users@jaxb.java.net

Re: Jaxb2 enum problem

From: Hello! hello <prosp4300_at_gmail.com>
Date: Thu, 20 May 2010 01:09:57 +0800

You can get this done by customize binding like following
    <jxb:bindings node="//xs:simpleType[@name='ProfileToggleType']">
        <jxb:typesafeEnumClass>
            <jxb:typesafeEnumMember name="Sync_Test"
value="Sync_Test"></jxb:typesafeEnumMember>
        </jxb:typesafeEnumClass>
    </jxb:bindings>

The generated java code from my side as following:
@XmlType(name = "ProfileToggleType")
@XmlEnum
public enum ProfileToggleType {

    @XmlEnumValue("SubscriptionProfile")
    SUBSCRIPTION_PROFILE("SubscriptionProfile"),
    *Sync_Test("Sync_Test");*
    private final String value;

    ProfileToggleType(String v) {
        value = v;
    }

    public String value() {
        return value;
    }

    public static ProfileToggleType fromValue(String v) {
        for (ProfileToggleType c: ProfileToggleType.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }

}

Hope this can help you

2010/5/18 Rochak Gupta <rochak005_at_gmail.com>

> Its an enum and we want ProfileToggleType to be an enum. In our XSD the
> enum value is Sync_Test but when doing unmarshalling it is comming as
> SYNC_TEST. But we want it to come as Sync_Test.
>
>
>
> On Tue, May 18, 2010 at 3:36 PM, Wolfgang Laun <wolfgang.laun_at_gmail.com>wrote:
>
>> What are the Java types of SYNC_TEST, profile, and
>> ProfileConstants.SYNCTEST_PROFILE?
>> Which should map to the schema type ProfileToggleType?
>>
>> Do you want ProfileToggleType to be an enum? Or do you want this type
>> to be java.lang.String?
>> And the same for all other schema types defined according to
>> <xs:restriction base="xs:string"><xs:enumeration ...>?
>>
>> -W
>>
>>
>> On Tue, May 18, 2010 at 10:59 AM, Rochak Gupta <rochak005_at_gmail.com>
>> wrote:
>> >
>> > HI,
>> >
>> >
>> >
>> > While updgrading JAXB1.x to JAXB2.1.10 migration , there is a problem
>> lies in the enumeration . I am pasting the snapshot of xsd which is catching
>> problem
>> >
>> >
>> >
>> > <xs:simpleType name="ProfileToggleType">
>> >
>> > <xs:restriction base="xs:string">
>> >
>> > <xs:enumeration value="SubscriptionProfile" />
>> >
>> > <xs:enumeration value="Sync_Test" />
>> >
>> > </xs:restriction>
>> >
>> > </xs:simpleType>
>> >
>> >
>> >
>> > When we do unmarshal a request
>> >
>> >
>> >
>> > com.att.osd.bbnms.bbcats.xml.synctest.schema.SyncTestRequest req =
>> >
>> >
>> (com.att.osd.bbnms.bbcats.xml.synctest.schema.SyncTestRequest) unmarshaller
>> >
>> > .unmarshal(request);
>> >
>> >
>> >
>> > When we get the respective value from the unmarshalled req object and do
>> subsequent processing as given below
>> >
>> >
>> >
>> > if (SYNC_TEST.equals(profile))
>> >
>> > {
>> >
>> > profile = ProfileConstants.SYNCTEST_PROFILE;
>> >
>> > }
>> >
>> >
>> >
>> > The comparison is failing because we expect as per to xsd “Sync_Test”
>> however we are getting “SYNC_TEST” . In JAXB1 we were getting as defined in
>> xsd i.e. “Sync_Test”
>> >
>> >
>> >
>> > So is there any way through some external binding we can stop jaxb
>> marshaller/unmarshaller to convert everything to bold and have exactly as
>> there in xsd .
>> >
>> > Thanks and regards,
>> > Rochak Gupta
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>