Note that there are some explanatory texts on larger screens.

plurals
  1. POXmlAdaptar in JAXB
    primarykey
    data
    text
    <p>I have the following <code>Enum</code> Class:</p> <pre><code>@XmlJavaTypeAdapter(value = PastMedicalHistoryAdapter.class) public enum PastMedicalHistory { Diabetes, Obesity, Smoking, COPD, CAD, PVD, Other }</code></pre> <p>and Generic Adapter:</p> <pre><code>public abstract class GenericEnumAdapter&lt;T extends Enum&gt extends XmlAdapter&lt;String, Enum&gt; { @Override public Enum unmarshal(String v) throws Exception { log.info("unmarshal: {}", v); return convert(v + ""); } public abstract T convert(String value); @Override public String marshal(Enum v) throws Exception { log.info("marshal: {}", v.name()); String s = "{\"" + v.name() + "\":" + true + "}"; return s; } }</code></pre> <p>and basic implementation with </p> <pre><code>public class PastMedicalHistoryAdapter extends GenericEnumAdapter&lt;PastMedicalHistory&gt; { @Override public PastMedicalHistory convert(String value) { return PastMedicalHistory.valueOf(value); } }</code></pre> <p>and I used it like this:</p> <pre><code>@Data @XmlRootElement(name = "Patient") public class Test { private List&lt;PastMedicalHistory&gt; history; public static void main(String[] args) throws Exception { JAXBContext cxt = JAXBContext.newInstance(Test.class); Marshaller mar = cxt.createMarshaller(); mar.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); mar.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json"); mar.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, Boolean.FALSE); Test t = new Test(); t.setHistory(Arrays.asList(PastMedicalHistory.CAD, PastMedicalHistory.Diabetes)); mar.marshal(t, System.out); } }</code></pre> <p>the problem, is Output for history is always null like this:</p> <pre><code>[exec:exec] 2013-09-29 12:13:18:511 INFO marshal: CAD 2013-09-29 12:13:18:522 INFO marshal: Diabetes { "history" : [ null, null ] }</code></pre> <p>I'm using Moxy <code>2.5.1</code> as <code>JAXB</code> Provider, so What I'm missing, or what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload