Hi Daniel,
I'm a little unclear on your problem description. You say that you're
getting NullPointerExceptions at runtime when you make the
DirectoryInformation elements optional - you do realize that if the
element isn't there the DirectoryInformation class instance won't be
created, right? Since the element is linked to the class instance that's
how optional works.
If you *always* want to have a DirectoryInformation class instance, even
when there's no element present, you're going to have to decouple the
element from the class instance. Just how you'd go about doing that
depends on whether you're only doing unmarshalling, or need to handle
both marshalling and unmarshalling (in the latter case you'd need to
have a test-method to say whether the DirectoryInformation element
should be generated while marshalling).
- Dennis
Daniel Lewis wrote:
Hello,
I am working on a large Java & XML based project and we are using JibX
for XML Binding. I am having a few problems doing Named abstract mappings.
We need an optional structure that we use in multiple places.
So for example we have:
<!-- Change Of Address -->
<mapping type-name="ChangeAddressOrderTypeForOrder1"
class="com.work.orders.transfers.ChangeAddressOrder" abstract="true">
<structure name="COA" field="wrslOrderType" usage="optional">
<structure map-as="COA_Common_Type" type="
com.work.orders.transfers.COAOrderDetails"/>
<structure name="DirectoryInformation"
field="directoryInformation" map-as="type1DirectoryInformation"/>
</structure>
<structure name="ChangeAddressOrderTypeForOrder2"
field="wbslOrderType" usage="optional">
<structure map-as="COA_Common_Type"
type="com.work.orders.transfers.COAOrderDetails"/>
<structure name="DirectoryInformation"
field="directoryInformation" map-as="type2DirectoryInformation" />
</structure>
</mapping>
The DirectoryInformations in ChangeAddressOrderTypeForOrder1 and
ChangeAddressOrderType ForOrder2 are the same java class (called
com.work.orders.transfers.DirectoryInformation), but their values
(annoyingly) have different values in the schema that we have to match
to. So we have created two mappings for the same class (called
type1DirectoryInformation and type2DirectoryInformation ). We aren't
embedding them into the above mappings because they are used all over
our jibx binding file.
The problem comes when we need to make the DirectoryInformations usage
equal optional, like this:
<structure name="DirectoryInformation"
field="directoryInformation" map-as="type1DirectoryInformation"
usage="optional"/>
When we do that, the JibX compiler works fine. But when we try to use
the mapping in a java class (such as our JUnit tests) it comes up with
a NullPointerException.
Has anyone had this problem before? If so have you fixed it? Or has
anyone else heard of this problem before?
I imagine that a similar thing has happened before, as I imagine its
quite a common structure.
If you need any more information let me know.
Thanks,
Daniel Lewis
* Analyst Programmer for Lifecycle Software Ltd (Newbury, UK):
http://www.lifecycle-software.com/
* Founder & President of the Brookes Computing Society (Oxford, UK):
http://www.brookescomputingsociety.org/
<http://www.brookescomputingsociety.org/>
* Intelligent Systems & Software Engineering Student (Oxford Brookes
University, Oxford, UK): http://cms.brookes.ac.uk/computing/
* Java, XML & Ruby developer for Linux/Unix, Mac & Windows
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users