I have no insight into why this is happening, but it seems to me that 
Strouble is asking for trouble.  I don't know your motivation in wanting 
such a class, but since it appears from your one example that there is 
some relation between the D and the S, would it not be possible to store 
only the double value and implement a getter for the String value in 
terms of the stored double?

The reason I ask you this is because I have such a class that implements 
a TelephoneNumber.  It stores it as a ten-digit string stripped of all 
formatting, and then has a getFormatted() method that returns a 
presentable representation.  If this is not going to work with Jibx, it 
would be good to know this before I get too far into it, and make other 
plans.

Will Brown wrote:
> Hello jibbixers,
>  
> here an annoying problem I need help solving.
>  
> I have defined a two-field Java class called Strouble, to hold a 
> double value and a String value. The idea is to keep both the raw data 
> (double) and the formatted (String) representation of one floating 
> point number in objects of this class.
>  
> I now have a quite complex data object called Company containing many 
> Stroubles which I want to be marshalled into XML showing both the 
> double and String value. This worked before (I'm quite sure) but after 
> I changed the structure of my binding file it stopped working.
>  
> Here are scaled down versions of the classes:
>  
> public class Company {
>   private Strouble xxx;
>   .....
>   public Company()
>   {
>     test = new Strouble();
>     test.setD(1234.5678);
>     test.setS("1,234.6");
>   }
> }
> public class Strouble {
>   protected double d;
>   protected String s;
>   public Strouble(double d, String s)
>   {
>     this.d = d;
>     this.s = s;
>   }
> }
>  
> And here is a scaled down version of the binding file:
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <binding direction="output">
>   <mapping class="x.y.z.Response" name="data">
>     <collection field="responseitems">
>       <structure type="x.y.z.ResponseItem">
>         <value field="error" name="error" usage="optional"/>
>         <structure field="company" name="company" usage="optional">
>           <value field="xxx" name="xxx"/>
>           .....
>         </structure>
>       </structure>
>     </collection>
>   </mapping>
>   <mapping class="x.y.z.Strouble" abstract="true">
>     <value field="d" name="d"/>
>     <value field="s" name="s"/>
>   </mapping>
> </binding>
>  
> And here is the output I get:
>  
> <?xml version="1.0" encoding="UTF-8" ?>
> <data>
>  <company>
>   <test>[EMAIL PROTECTED]</test>
>   .....
>  </company>
> </data>
>  
> As you see, I don't get the d and s fields of the Strouble type, but 
> rather something that looks like a pointer reference. The Company 
> object is embedded like so:
>  
> class Response {                          // the outermost <structure>
>   ArrayList<ResponseItem> responseitems;  // the <collection>
> }
>  
> class ResponseItem {                      // the inner <structure>
>   String error;
>   Company company;
> } 
>  
> The idea is that a Response consists of several response-items, and a 
> response-item is either an error message, or a Company. They are both 
> usage="optional" so I always let precisely one of them be null. I had 
> an earlier version where the company was not so deeply nested and then 
> I think the Strouble marshalling worked fine.
>  
> Why is my mapping ignored? What can I do about it?
>  
> Best regards,
> Doc
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
> Don't miss this year's exciting event. There's still time to save $100. 
> Use priority code J8TL2D2. 
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to