Hello list

Unmarshaller unmarshaller = new Unmarshaller(CharRequest.class);
unmarshaller.setMapping(mapping);
unmarshaller.setWhitespacePreserve(true); <--

Should be added to avoid my reported situation
Diogo

-----------------------------------
Diogo Bacelar Quintela
EF - Tecnologias de Informa��o, Lda.
Av. Ant�nio Serpa, 26 - 4� Dto.
1050-027 Lisboa, Portugal
Tel: (+351) 217 827 800
Fax: (+351) 217 827 830
Email: [EMAIL PROTECTED]
PGP: 0xF51A5AB9 

-----Original Message-----
From: Marcell Manfrin Barbacena [mailto:[EMAIL PROTECTED] 
Sent: quinta-feira, 5 de Maio de 2005 0:57
To: [email protected]
Subject: Re: [castor-user] [XML] char not being correct unmarshalled

Hello Diogo,

I think thats is because u cannot get a meaning about charS like
space, carrier return, line break and others because they are part of
the XML structure.
One way to export charS like that is to translate to unicode before
marshalling.

Best regards.

On 5/4/05, Diogo Quintela (EF) <[EMAIL PROTECTED]> wrote:
> Hello
>         I have a char field that gets mapped into a XML element. If a set
> the value of that char to ' ', I cannot unmarshall the struct correctly
back
> (If another char is used, it works fine... although I haven't tested with
> more ...)
>         The prof is simple. Just follow the next clipping areas... eh.
>         Only have 'castor-0.9.6-xml.jar' in classpath.
> TIA
>         Diogo Quintela
> 
> ----------------------------------
> package pt.ef.castor;
> public class CharRequest {
>   public char reenforceOption;
>   public CharRequest() {
>     this.reenforceOption=' ';
>   }
>   public char getReenforceOption() {
>     return this.reenforceOption;
>   }
>   public void setReenforceOption(char reenforceOption) {
>     this.reenforceOption=reenforceOption;
>   }
> 
>     public String toString() {
>         StringBuffer buffer = new StringBuffer();
>         buffer.append("[CharRequest:");
>         buffer.append(" reenforceOption: ");
>         buffer.append(reenforceOption);
>         buffer.append(" (");
>         buffer.append(Character.getType(reenforceOption));
>         buffer.append("-");
>         buffer.append(Character.isSpaceChar(reenforceOption));
>         buffer.append("-");
>         buffer.append((int)reenforceOption);
>         buffer.append(")]");
>         return buffer.toString();
>     }
> }
> 
> ----------------------------------
> package pt.ef.castor;
> public class CharRequestTest {
>     public static void main(String[] args) {
>         try {
>             Mapping mapping = new Mapping();
>             mapping.loadMapping("CharRequest.xml");
> 
>             CharRequest req = new CharRequest();
> 
>             StringWriter strW = new StringWriter();
>             Marshaller marsheler = new Marshaller(strW);
>             marsheler.setMapping(mapping);
>             marsheler.marshal(req);
> 
>             System.out.println("xml=" + strW.toString());
> 
>             Unmarshaller unmarshaller = new
Unmarshaller(CharRequest.class);
>             unmarshaller.setMapping(mapping);
> 
>             CharRequest req2 = (CharRequest) unmarshaller.unmarshal(
>                         new StringReader(strW.toString()));
> 
>             System.out.println("req.toString() =" + req);
>             System.out.println("req2.toString()=" + req2);
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
> 
> ----------------------------------
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
> 1.0//EN" "http://castor.exolab.org/mapping.dtd";>
> <mapping>
>     <class name="pt.ef.castor.CharRequest" auto-complete="false">
>         <map-to xml="Request"/>
>         <field name="reenforceOption" type="char">
>             <bind-xml name="Test" node="element" />
>         </field>
>     </class>
> </mapping>
> ----------------------------------
> xml=<?xml version="1.0" encoding="UTF-8"?>
> <Request><Test> </Test></Request>
> req.toString() =[CharRequest: reenforceOption:   (12-true-32)]
> req2.toString()=[CharRequest: reenforceOption: [can't C&P weird char]
> (15-false-0)]
> 
> -----------------------------------
> Diogo Bacelar Quintela
> EF - Tecnologias de Informa��o, Lda.
> Av. Ant�nio Serpa, 26 - 4� Dto.
> 1050-027 Lisboa, Portugal
> Tel: (+351) 217 827 800
> Fax: (+351) 217 827 830
> Email: [EMAIL PROTECTED]
> PGP: 0xF51A5AB9
> 
> 


-- 
"Nobody knows who i really am
 I never felt this empty before
 And if I never need someone to come along
 Who's gonna comfort me and keep me strong?"
--
Marcell Manfrin Barbacena
[EMAIL PROTECTED]
MSN Messenger: [EMAIL PROTECTED]
ICQ UIN: 63671762
Skype: callto://marcell84bruk
+55 (83) 8808-8555 (Oi)

Reply via email to