Hi Jonas, When you use the ident="def"/"ref" technique in JiBX it expects you to have the definition for each reference present in your document. In your case, you're just defining the account id values (not referencing them) and just referencing the customer id values (not defining them). There's really no reason to use ident in this case, and if you instead just remove the ident attributes and treat the id values as simple strings you should get what you want.
- Dennis Dennis M. Sosnoski SOA and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 [EMAIL PROTECTED] wrote: > Hello > > I'm trying to marshal/unmarshal part of an object graph where references to > objects that shall not be marshalled are replaced by IDs that are unique per > type. As an example, let us assume we have the following two classes: > > public class Customer { > private String id; > private String name; > // getters and setters > } > > public class Account { > private String id; > private Customer customer; > private double balance; > // getters and setters > } > > That is, each customer has a unique ID string, and a customer can have > multiple accounts, where each account has a unique ID string as well. > > Let's now say we want to create an XML representation of all the accounts in > the system without marshalling the customer objects themselves, but only > their IDs. For example, the XML could look as follows: > > <accounts> > <account> > <id>A1</id> > <customer-id>C1</customer-id> > <balance>500.0</balance> > </account> > <account> > <id>A2</id> > <customer-id>C1</customer-id> > <balance>-23.0</balance> > </account> > <account> > <id>A3</id> > <customer-id>C2</customer-id> > <balance>11.0</balance> > </account> > </accounts> > > I achieved something like this by defining a mappings as follows: > > <mapping name="customer" class="Customer"> > <value name="id" field="id" ident="def"/> > <value name="name" field="name"/> > </mapping> > > <mapping name="account" class="Account"> > <value name="id" field="id" ident="def"/> > <value name="customer-id" field="customer" ident="ref"/> > <value name="balance" field="balance"/> > </mapping> > > <mapping name="accounts" class="AccountList"> > <collection field="items" item-type="Account" > factory="org.jibx.runtime.Utility.arrayListFactory"> > </mapping> > > where class AccountList is a helper class and defined as follows: > > public class AccountList { > private List<Account> items; > // getters and setters > } > > Now, my problem is the unmarshalling. I would have expected JiBX to create a > series of Account objects and referenced Customer objects, where the Customer > objects of course have only set the id property (since nothing else can be > derived from the XML data). In the specific example above, I would have > expected JiBX to create three Account objects (A1, A2, and A3) as well as two > Customer objects (C1, C2), where A1 and A2 reference C1 and A3 references C2. > However, no Customer objects are created and the references in the Account > objects are set to null. > > How would you go about this? What is the best way to achieve something like > this? > > Thanks in advance! > > -Jonas > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users