Hi Dennis,

Thanks for your reply. Yes the solution you expose at the end of your email would satisfy my current needs. I wanted to avoid modifying my classes but will do so if the possibility is not available right now.

The problem comes from the fact that my objects need to be localized (to set a language) in order to be set. Therefore, jibx's unmarshaller cannot know which language to set on creation.

What I have done to workaround this is that I have added a xml:lang attribute in my xml file and the following definition on my mapping file:

<value style="attribute" ns="http://www.w3.org/XML/1998/namespace"; name="lang" get-method="getLocale" set-method="setLocale" usage="optional"/>

so that the ItineraryRendition can be localized during the unmarshalling. This works fine and is a logical approach so I don't necessarily need the fix you were talking about...although it could be practical for similar cases.

Thanks again,

Fran�ois

Dennis Sosnoski wrote:

At present you can use the factory-method attribute to return an existing object, though it's kind of awkward - use a factory-method that takes the containing object, then check the type of that object (if necessary) to see if it has an existing instance you want to return.

Doing the modifications the way you've illustrated below (with a round trip through XML) is going to be really ugly, though. Can't you modify the existing object in-place to have the changes you want? If you really need to change things around perhaps you're better off using a custom marshaller/unmarshaller to just handle the initial creation of the ItineraryRendition.

You can also use a post-set method for the ItineraryRendition to handle the changes. Right now that method has to be a member method of the ItineraryRendition class; in the future JiBX may allow a static method that takes the actual class instance as an argument, so that it doesn't have to be a member method (and you don't need to modify the target class). Would that work for your needs?

 - Dennis

Fran�ois Eric wrote:

Hello,

I'm having trouble unmarshalling one of my xml files. The bindings are correct and all but the problem is that the"POJO" being created by the unmarshalling needs to be altered before the unmarshalling is done. Therefore I would need to pass an existing instance of my class and have jibx's unmarshaller populate it:
ItineraryRendition itinerary = new ItineraryRendition();
... (make modifications to itinerary)
output = (ItineraryRendition) unmarshallingContext.unmarshalDocument(itinerary, new StringReader(stringWriter.toString()));


In the previous example, the stringWriter contains the XML document. As you can see, I have passed the itinerary to the unmarshalling document (which is not an existing method).
Is there a way, I can mime such a behaviour? To give an existing instance to jibx instead of having jibx use the default constructor of the object?


Thank you,

Fran�ois




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users







------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to