Anotaciones JAXB para enumeraciones

I have the following enum definition:

public enum MyEnumeration{

  ENUM_ONE("1","foo"),
  ENUM_TWO("2","bar");

  private String code;
  private String description;

  public String getDescription()
  {
     return this.description;
  }

  public String getCode()
  {
     return this.code;
  }    
}

And I want to annotate it with Jaxb annotations so it will be marshalled into the following xml.

<myenumeration>
  <code>...</code>
  <description>...</description>
</myenumeration>

I've tried several approaches, but wasn't succesful. Any ideas? Thanks in advance!

preguntado el 28 de agosto de 12 a las 14:08

1 Respuestas

Podrías escribir un XmlAdapter that converts the enum into a domain object with those properties. For examples of using XmlAdapter ver:

Respondido 28 ago 12, 14:08

Thanks for your answer, but your link shows me several blogposts. Which would you suggest to review? Or else how would I start doing this? - bjarne77

@Bjarne77 - This would be a good one to use: blog.bdoughan.com/2010/12/jaxb-and-immutable-objects.html - bdoughan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.