Hi Angelo, you can use it like this:
public class MyClass {
public MyClass(Whatever what ever) { }
public MyClass() {}
public String toXML() {
ByteArrayOutputStream stream = new ByteArrayOutputStream() ;
try {
XMLEncoder encoder = new XMLEncoder(new
BufferedOutputStream(stream));
encoder.writeObject(this);
encoder.close();
} catch (Exception e) {
logger.error(e);
}
return stream.toString();
}
}
you can change the ByteArrayOutputStream implementation for a
FileOutPutStream, if you're using a custom constructor in your
implementation you should write a default constructor for it.
public class MyDecoder {
public MyClass decode(String myClassToXmlString) {
XMLDecoder d = new XMLDecoder(new BufferedInputStream(new
ByteArrayInputStream myClassToXmlString.getBytes())));
Object result = d.readObject();
d.close();
return (MyClass) result ;
}
}
Angelo Chen wrote:
>
> Hi Fidel,
>
> I have some problem with XMLEncoder:
>
> http://www.nabble.com/T5%3A-Can-XMLEncoder-be-used-with-T5-app--tf4362923s302.html
>
> how to use this xmlencode to avoid those exceptions? Thanks,
>
> A.C.
>
>
> Fidel Chavarria wrote:
>>
>>
>>
>> Hi,
>> you can use XMLEncoder/Decoder from java Api.
>>
>> make sure you don't do this in a page "delegate" this functionality to
>> your the infrastructure layer.
>>
>>
>> Angelo Chen wrote:
>>>
>>> Hi,
>>>
>>> I have this need to write/read some java objects to xml files in T5, can
>>> anybody recommend one that works? Thanks.
>>>
>>> A.C.
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/T5%3A-POJO-to-xml-lib-tf4363192.html#a12465657
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]