users@jersey.java.net

[Jersey] JAXB XmlAdapter with _at_Inject

From: DiFrango, Ronald <Ronald.DiFrango_at_capitalone.com>
Date: Wed, 9 Mar 2016 18:38:27 +0000

All,

We recently upgraded from:

<eclipse.persistence.core.version>2.5.2</eclipse.persistence.core.version>
<jersey2.version>2.17</jersey2.version>
<hk2.version>2.4.0-b10</hk2.version>

to:

<eclipse.persistence.core.version>2.6.1</eclipse.persistence.core.version>
<jersey2.version>2.22.1</jersey2.version>
<hk2.version>2.4.0-b34</hk2.version>

I’m not sure if this is a Jersey, Moxy, or HK2 issue, but I’m going to try to explain what we have:

@XmlJavaTypeAdapter(A.MyXmlAdapter.class)
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class A {
   @Named
    public static class MyXmlAdapter extends XmlAdapter<String, ReferenceId> {
        @Inject
        private MyService service;

        @Override
        public A unmarshal(String value) throws Exception {
            return service.convertToA(value);
        }

        @Override
        public String marshal(A a) throws Exception {
            return service.convertToString(value);
        }
    }
}

Now on my resource if I declare it as t

public A createOne(A a) {
        return a;
}

The service != null on MyXmlAdapter so it works

Another variation that also works is:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({A.class})
public class B {
   private List<A> entries;

   public List<A> getEntries() {
        return entries;
    }
}

But if I declare the type as of list:

 public A createOne(List<A> a) {
        return a;
}

service == null on MyXmlAdapter so it fails.

Thanks,

Ron DiFrango

________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.