Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-171

Jaxb2Marshaller.supports(Class clazz) is too eager

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.0.1
    • Component/s: OXM
    • Labels:
      None

      Description

      When using multiple Jaxb2Marshallers for multiple endpoints, first encountered Jaxb2Marshaller is always used, because it's "support" method accepts every Jaxb class. My proposition for improvement is:

      public boolean supports(Class clazz) {
      boolean isJaxbClass = clazz.getAnnotation(XmlRootElement.class) != null

      JAXBElement.class.isAssignableFrom(clazz);
      if (isJaxbClass) {
      if (StringUtils.hasLength(getContextPath())) {
      String pckgName = clazz.getPackage().getName();
      StringTokenizer st = new StringTokenizer(getContextPath(), ":");
      while (st.hasMoreTokens())
      Unknown macro: { if (st.nextToken().equals(pckgName)) { return true; }
      }
      } else if (!ObjectUtils.isEmpty(classesToBeBound)) {
      for (Class clazzToBeBo : classesToBeBound) {
      if (clazzToBeBo.equals(clazz)) { return true; } }

      } else

      { throw new IllegalArgumentException( "setting either contextPath or classesToBeBound is required"); }

      }
      return false;
      }

        Activity

        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Fixed, though in a slightly different way: using the JAXBIntrospector. This has the added advantage that subclasses of JAXB elements are also supported, and that we use the JAXB2 'native' way to determine whether a class is supported.

        Unfortunately, we need to instantiate classes in order to pass them to the JAXBIntrospector. However, we cache the results (supported or not), so instantiation is only done once.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Fixed, though in a slightly different way: using the JAXBIntrospector. This has the added advantage that subclasses of JAXB elements are also supported, and that we use the JAXB2 'native' way to determine whether a class is supported. Unfortunately, we need to instantiate classes in order to pass them to the JAXBIntrospector. However, we cache the results (supported or not), so instantiation is only done once.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing 1.0.1 issues.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing 1.0.1 issues.

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            anthavio Martin Vanek
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: