jaxb
  1. jaxb
  2. JAXB-103

multiple namespaces are serialized

    Details

    • Type: New Feature New Feature
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0 EA1
    • Fix Version/s: not determined
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      103

      Description

      have two separate packages
      com.company1.doc
      and com.company2.doc

      every package contains namespace definition (in package-info.java):
      @javax.xml.bind.annotation.XmlSchema(namespace = "http://company1.com/doc")
      package com.company1.doc;

      and
      @javax.xml.bind.annotation.XmlSchema(namespace = "http://company2.com/doc")
      package com.company2.doc;

      I initialize JAXBContext using JAXBContext.newInstance("com.company1:com.company2");

      Then I construct java objects in both packages:

      Problem is then I unmarshall documents of one package I see namespace of another
      package:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <Document xmlns:ns2="http://company1.com/doc" xmlns:ns3="http://company2.com/doc">
      ...

      Is it possible to avoid printing of unused namespace ?

      1. jaxb.index
        0.0 kB
        ramazanyich2
      2. package-info.java
        0.1 kB
        ramazanyich2
      3. package-info.java
        0.1 kB
        ramazanyich2
      4. test.xml
        0.2 kB
        ramazanyich2
      5. TestClass1.java
        0.5 kB
        ramazanyich2
      6. testJaxb.java
        0.6 kB
        ramazanyich2

        Activity

        Hide
        mindchi added a comment -

        I'm requesting that this issue be reopened as having the extraneous namespaces
        causes problems when using JAXB as the data binding framework for CXF. Firstly,
        I think it is unacceptable to have a solution which changes your data. If I
        take an XML file read it in and write it back out, I should end up with exactly
        the same file. Not a file that has extra stuff in it. This reason alone should
        be enough to warrant a fix.

        I am writing some web service code using CFX and JAXB. I check my code all the
        way to the point where I include it as an element of a larger document that
        gets passed into CFX framework for handling web service processing. When it
        comes out, it has extra tags in it. It is sent to publish and subscribe server.
        When I try to read the data when I retrieve it from the server, CXF produces a
        SAX parse exception due to one of the extraneous namespaces which it wasn't
        expecting. Now, it may be possible for me to intercept the data and remove the
        extranuous namespace definitions, but this is an enterprise system, and I
        cannot expect every other application to do this. Up until this point, my
        experience with JAXB has been good. I like the performance, however, this issue
        basically renders JAXB useless to me on this project. I would like to continue
        to use JAXB, however, I don't expect this to be fixed anytime soon, so I will
        need to look into using some other data binding framework, perhaps XMLBeans
        with CXF.

        Please consider correcting this problem so I can continue using JAXB in
        conjunction with CXF.

        Show
        mindchi added a comment - I'm requesting that this issue be reopened as having the extraneous namespaces causes problems when using JAXB as the data binding framework for CXF. Firstly, I think it is unacceptable to have a solution which changes your data. If I take an XML file read it in and write it back out, I should end up with exactly the same file. Not a file that has extra stuff in it. This reason alone should be enough to warrant a fix. I am writing some web service code using CFX and JAXB. I check my code all the way to the point where I include it as an element of a larger document that gets passed into CFX framework for handling web service processing. When it comes out, it has extra tags in it. It is sent to publish and subscribe server. When I try to read the data when I retrieve it from the server, CXF produces a SAX parse exception due to one of the extraneous namespaces which it wasn't expecting. Now, it may be possible for me to intercept the data and remove the extranuous namespace definitions, but this is an enterprise system, and I cannot expect every other application to do this. Up until this point, my experience with JAXB has been good. I like the performance, however, this issue basically renders JAXB useless to me on this project. I would like to continue to use JAXB, however, I don't expect this to be fixed anytime soon, so I will need to look into using some other data binding framework, perhaps XMLBeans with CXF. Please consider correcting this problem so I can continue using JAXB in conjunction with CXF.
        Hide
        aempinheiro added a comment -

        Referring to the comment before, altering the existing xml means that, if I open a signed xml jaxb will change it and its' signature won't be valid anymore.

        This means that this issue represents quite a big problem.

        Show
        aempinheiro added a comment - Referring to the comment before, altering the existing xml means that, if I open a signed xml jaxb will change it and its' signature won't be valid anymore. This means that this issue represents quite a big problem.
        Hide
        rustamabd added a comment -

        I disagree with the reasoning provided by 'kohsuke', performance can have different meaning, for some users network throughput has higher importance than CPU cycles. For example take small secured services, these have lots of OASIS headers and small payloads. Unnecessary namespace overhead in these is big, while the overhead of traversing a dozen nodes would be negligible.

        I propose to have an optional feature (with a possibility to turn it on and off) to traverse the tree and eliminate unnecessary namespace declarations. This can be made even smarter; e.g. stop traversing after reaching 100th node.

        Show
        rustamabd added a comment - I disagree with the reasoning provided by 'kohsuke', performance can have different meaning, for some users network throughput has higher importance than CPU cycles. For example take small secured services, these have lots of OASIS headers and small payloads. Unnecessary namespace overhead in these is big, while the overhead of traversing a dozen nodes would be negligible. I propose to have an optional feature (with a possibility to turn it on and off) to traverse the tree and eliminate unnecessary namespace declarations. This can be made even smarter; e.g. stop traversing after reaching 100th node.
        Hide
        thst added a comment -

        I am wondering why it would not be possible to keep a list of used namespaces during production and add them in a second step to the final dom. This way there is no need to traverse the whole tree a second time, only a visit in the documentroot as a last step.

        I understand that this would not work on a streaming output, but treewalking would have the same issue.

        Show
        thst added a comment - I am wondering why it would not be possible to keep a list of used namespaces during production and add them in a second step to the final dom. This way there is no need to traverse the whole tree a second time, only a visit in the documentroot as a last step. I understand that this would not work on a streaming output, but treewalking would have the same issue.
        Hide
        ajsmen added a comment -

        @kohsuke:
        > In 1.0, we did what ramazanyich2 wanted us to do — namely, declare namespaces
        > lazily on-demand, only when it's necessary. Often this results in namespaces
        > declared multiple places in sub-trees, and many people weren't happy with this.

        What about lazily on-demand add namespaces to some sort of set during document creation and at the end append all of them to the root element?

        Show
        ajsmen added a comment - @kohsuke: > In 1.0, we did what ramazanyich2 wanted us to do — namely, declare namespaces > lazily on-demand, only when it's necessary. Often this results in namespaces > declared multiple places in sub-trees, and many people weren't happy with this. What about lazily on-demand add namespaces to some sort of set during document creation and at the end append all of them to the root element?

          People

          • Assignee:
            Martin Grebac
            Reporter:
            ramazanyich2
          • Votes:
            11 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated: