jaxb
  1. jaxb
  2. JAXB-971

Regression: annotation @XmlJavaTypeAdapters on package is ignored since JAXB v2.2.4-1

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: 2.2.5, 2.2.6, 2.2.7
    • Fix Version/s: None
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Windows 7 x64; JDK 1.6 and JDK 1.7

      Description

      JAXB v2.2.4-1 was the last version that takes into account @XmlJavaTypeAdapters annotation (applied on package). All later JAXB versions ignore this annotation - supplied XmlAdapters are not being used.

      Attached is an Ant project, adapted from JAXB sample "j2s-xmlAdapter".
      Original sample code (working OK in all JAXB versions) had:

      @XmlRootElement
      @XmlType(name="KitchenWorldBasketType")
      public class KitchenWorldBasket {
          @XmlJavaTypeAdapter(AdapterPurchaseListToHashMap.class)
          HashMap basket = new HashMap();
          ...
      

      and

      public class Main {
          public static void main(String[] args) throws Exception {
              JAXBContext jc = JAXBContext.newInstance(KitchenWorldBasket.class);
              ...
      

      The attached project has these modifications:

      @XmlRootElement
      @XmlType(name="KitchenWorldBasketType")
      public class KitchenWorldBasket {
          //@XmlJavaTypeAdapter(AdapterPurchaseListToHashMap.class)
          @XmlElement(type = PurchaseList.class)
          public LinkedHashMap basket = new LinkedHashMap();
          ...
      

      and

      @XmlJavaTypeAdapters({
              @XmlJavaTypeAdapter(value = AdapterPurchaseListToHashMap.class, type = LinkedHashMap.class)
      })
      package shoppingCart;
      
      import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
      import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
      import java.util.LinkedHashMap;
      

      and

      public class Main {
          public static void main(String[] args) throws Exception {
              JAXBContext jc = JAXBContext.newInstance(KitchenWorldBasket.class.getPackage().getName());
              ...
      

      Running the attached project with JAXB v2.2.4-1 gives:

      run:
           [echo] Running the sample application...
           [java] KitchenWorldBasket:
           [java] key: 9027   value: glasstop stove in black
           [java] key: 10424  value: backsplash kit in black
           [java] key: 288    value: wooden spoon
           [java] key: 289    value: salt and pepper shakers in yellow
           [java]
           [java] <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
           [java] <kitchenWorldBasket>
           [java]     <basket>
           [java]         <item key="9027">glasstop stove in black</item>
           [java]         <item key="10424">backsplash kit in black</item>
           [java]         <item key="288">wooden spoon</item>
           [java]         <item key="289">salt and pepper shakers in yellow</item>
           [java]     </basket>
           [java] </kitchenWorldBasket>
      
      BUILD SUCCESSFUL
      

      Running with JAXB v2.2.5, v2.2.6 and v2.2.7:

      run:
           [echo] Running the sample application...
           [java] KitchenWorldBasket:
           [java]
           [java] <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
           [java] <kitchenWorldBasket>
           [java]     <basket/>
           [java] </kitchenWorldBasket>
      
      BUILD SUCCESSFUL
      

      There is no difference, whether namespaces are being used or not. I stumbled on this bug working with WebServices and JAX-WS/JAXB bindings (where namespaces are being used).

      Additionally, annotation @XmlJavaTypeAdapter is being ignored on classes too (though I do not have a sample test case).

      It seems, that @XmlJavaTypeAdapter is being taken into account only when it is applied on class fields.

        Activity

        Hide
        Iaroslav Savytskyi added a comment -

        Hi,

        Thanks a lot for reporting.

        May be this problem occurred because of APT rewrite in 2.2.5. I have to check.

        Show
        Iaroslav Savytskyi added a comment - Hi, Thanks a lot for reporting. May be this problem occurred because of APT rewrite in 2.2.5. I have to check.
        Hide
        donatasc added a comment -
        Show
        donatasc added a comment - Sample project can be downloaded from: http://www.mif.vu.lt/~donatas/private/j2s-xmlAdapter-onPackage.zip

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            donatasc
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: