Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] XML attribute mapping to Java 5 Enum

Hi Leon,

This can be accomplished by adding a Converter to your mapping for" type". Assuming you have an XMLDirectMapping for your type attribute with the XPath @type, you can add an org.eclipse.persistence.mappings.converters.EnumTypeConverter to that mapping which will handle the conversion of the String value back to the Enum value and vice-versa.

Hope this is helpful,

-Matt


----- Original Message ----- From: "Leon Derks" <leon.derks@xxxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, April 10, 2008 8:10 AM
Subject: [eclipselink-users] XML attribute mapping to Java 5 Enum


I want to convert a attribute value to a Java 5 enum.

Can someone explain to me how this can be done?

For example I want convert type="minimum" into a ValueType.MINIMUM.

<Value type="minimum" value="-25"/>

public enum ValueType {

  MAXIMUM("Maximum"), MINIMUM("Minimum"), NOMINAL("Nominal");

  private final String description;

  private CharacteristicValueType(String description) {
      this.description = description;
  }

  public String value() {
      return description;
  }

  public String toString() {
      return description;
  }

}
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top