eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
204 stars 111 forks source link

multiple namespaces are serialized #103

Open Tomas-Kraus opened 19 years ago

Tomas-Kraus commented 19 years ago

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"?>

... Is it possible to avoid printing of unused namespace ? #### Environment Operating System: All Platform: All #### Affected Versions [2.0 EA1]
Tomas-Kraus commented 6 years ago
Tomas-Kraus commented 19 years ago

@glassfishrobot Commented Reported by ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented kohsuke said: Hmm.

Would it be possible for you to try the latest nightly build? I remember fixing an issue like this some time ago, and I couldn't reproduce the problem with the current snapshot of the JAXB RI.

If it still doesn't work, please reopen the bug so that it gets our attention.

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=57) test class file which produces output

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=58) class file for first package

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=59) class file for second package

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=60) package info for second package

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=61) package info for first package

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: Created an attachment (id=62) result of execution

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ramazanyich2 said: I tried it with lates build ( dated by 8 november) but in result I still have all namespaces. I attached all files to the issue. Run testJaxb.java and you will have test.xml as result. It will have <ns2:test1 xmlns:ns2="http://company1.com" xmlns:ns3="http://company2.com"> xmlns:ns3="http://company2.com" is unwanted as object TestClass2 was not created.

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented ktrapszo said: Using 4/19/2006 build, this is still an issue.

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented kohsuke said: This is actually the expected behavior.

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.

We can't make it any smarter, as in short of traversing the whole object tree, The marshaller won't be able to discover all the namespaces in use. Such traversal would be very costly.

So in 2.0 we decided to change the behavior to always declare all the statically known namespaces upfront. This also made the namespace management inside the marshaller simpler, contributed to the overall performance improvement.

Given those background, at this point we are not planning to change this behavior.

Tomas-Kraus commented 14 years ago

@glassfishrobot Commented mindchi said: 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.

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented aempinheiro said: 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.

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented rustamabd said: 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.

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented thst said: 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.

Tomas-Kraus commented 12 years ago

@glassfishrobot Commented ajsmen said: @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?

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: jaxb.index Attached By: ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: package-info.java Attached By: ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: package-info.java Attached By: ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: test.xml Attached By: ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: TestClass1.java Attached By: ramazanyich2

Tomas-Kraus commented 18 years ago

@glassfishrobot Commented File: testJaxb.java Attached By: ramazanyich2

Tomas-Kraus commented 19 years ago

@glassfishrobot Commented Was assigned to snajper

Tomas-Kraus commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-103

Tomas-Kraus commented 7 years ago

@rhdsmnd Commented What's the consensus around adding a setting that has the marshaller run an extra pass through the document and eliminate unused namespaces?

Tomas-Kraus commented 6 years ago

@epochcoder Commented We are in a process of converting of converting a lot of legacy code that was using Apache XMLBeans to JAXB, this was a feature provided there OOB; and is stopping us from doing a (clean) migration.

We now have workarounds to only create a JAXBContext for the classes involved in (un)marshalling;

Providing a feature toggle for this new functionality would be great

Xyaren commented 5 years ago

Ist there any update on this issue ?

rhdsmnd commented 4 years ago

I ended up writing a simple SAX parser which removed unused namespaces. Worked fine