Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JiBX 1.1.5
-
Fix Version/s: JiBX 1.1.6
-
Component/s: core
-
Labels:None
-
Environment:Windows XP, Java 1.5.0_10
-
Number of attachments :
Description
Just tried upgrading to JIBX 1.1.5 from 1.0.1 and hit this problem.
I have a binding that is direction="output" and I have three hibernate classes that map to the same element name.
When I try to bind compile, there is an exception thrown because the equals method in NameAttributes, when the name is the same, resorts to the namespace to distinguish the two objects, but the namespace has not been set on either of them.
[java] Error running binding compiler
[java] java.lang.NullPointerException
[java] at org.jibx.binding.model.NameAttributes.equals(NameAttributes.java:184)
[java] at java.util.HashMap.eq(HashMap.java:299)
[java] at java.util.HashMap.containsKey(HashMap.java:381)
[java] at org.jibx.binding.model.DefinitionContext.addMappedName(DefinitionContext.java:551)
[java] at org.jibx.binding.model.RegistrationVisitor.visit(RegistrationVisitor.java:183)
[java] at org.jibx.binding.model.TreeContext.tourTree(TreeContext.java:171)
[java] at org.jibx.binding.model.TreeContext.tourTree(TreeContext.java:232)
[java] at org.jibx.binding.model.RegistrationVisitor.visitTree(RegistrationVisitor.java:96)
[java] at org.jibx.binding.model.BindingElement.runValidation(BindingElement.java:755)
[java] at org.jibx.binding.model.BindingElement.validateBinding(BindingElement.java:819)
[java] at org.jibx.binding.Utility.validateBinding(Utility.java:228)
[java] at org.jibx.binding.Utility.loadBinding(Utility.java:269)
[java] at org.jibx.binding.Utility.loadFileBinding(Utility.java:413)
[java] at org.jibx.binding.Compile.compile(Compile.java:296)
[java] at org.jibx.binding.Compile.main(Compile.java:385)
I understand that it is not possible to unmarshal an incoming element to one of multiple classes, since there is not enough information to figure out which class to instantiate. But it would be useful to be able to marshal multiple classes to the same element name.
The attached code has a target outputIssue that causes the exception
Activity
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | JiBX 1.1.6 [ 14068 ] | |
| Resolution | Fixed [ 1 ] | |
| Assignee | Dennis Sosnoski [ dsosnoski ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Status | Resolved [ 5 ] | Closed [ 6 ] |
I have the same problem, but I'm not restricted to marshalling.
Basically, I have a small 'control' file containing some metadata and a related (possibly very large)
'data' file, both using the same element name. Most important, the control file contains the path
to the data file.
<binding value-style="attribute">
<mapping name="foo" class="FooControl">
<value name="path" field="pathToData"/>
</mapping>
<mapping name="foo" class="FooData">
<!-- lots of stuff here -->
</mapping>
</binding>
A server application feeds control files to my program, and using the contained path my program knows where to
find the real data. So when I read/write an XML file, I know exactly what class to unmarshal to/marshal from, and
simply use two IBindingFactory instances to read and write both kind of files:
IBindingFactory controlFactory = BindingDirectory.getFactory(FooControl.class);
IBindingFactory dataFactory = BindingDirectory.getFactory(FooData.class);
This works great with JiBX 1.0.2.
1.1.3 complains:
Error: Duplicate mapping name not allowed for unmarshalling; on mapping element at (line 6, col 37, in binding.xml)
Error running binding compiler
org.jibx.runtime.JiBXException: Binding binding.xml is unusable because of validation errors
at org.jibx.binding.Utility.loadBinding(Utility.java:346)
at org.jibx.binding.Utility.loadFileBinding(Utility.java:413)
at org.jibx.binding.Compile.compile(Compile.java:296)
at org.jibx.binding.Compile.main(Compile.java:385)
1.1.5 fails with the NullPointerException from the original bug report.