You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/09/01 03:12:04 UTC

T5: POJO to xml lib

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#a12436353
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Guoguo,

XStream works well under T5, problem now is, it does not handle UTF-8, any
tips on this too? Thanks.
A.C.


蝈蝈龙 wrote:
> 
> Indeed Castor is more portable than XStream. But XStream is stronger and
> more simpler.
> So you have to bear it's slightly bigger size.
> But I find all the dependency jars of XStream are about 3m not 5m. And
> cglib-nodep-2.1_3.jar,dom4j-1.6.1.jar,jdom-1.0.jar may be also used in
> other
> place.
> 
> Cheers
> Guoguo Long
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-POJO-to-xml-lib-tf4363192.html#a12440006
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by 蝈蝈龙 <el...@gmail.com>.
Indeed Castor is more portable than XStream. But XStream is stronger and
more simpler.
So you have to bear it's slightly bigger size.
But I find all the dependency jars of XStream are about 3m not 5m. And
cglib-nodep-2.1_3.jar,dom4j-1.6.1.jar,jdom-1.0.jar may be also used in other
place.

Cheers
Guoguo Long



2007/9/1, Angelo Chen <an...@yahoo.com.hk>:
>
>
> Hi Jonathan,
>
> I tried XStream as suggested by 蝈蝈龙, it works, but library size is big
> around 5mb added, how big is the Castor? one nice thing about XSream is, I
> don't have to write any xml mapping, same with Castore? Thanks.
>
> A.C.
>
> Jonathan Barker wrote:
> >
> >
> > Try Castor at www.castor.org
> >
> > It's a Java <-> XML tool that favors the Java side.  It's easy by
> default,
> > but can be very flexible. I use this the most.
> >
> > If you want to favor the XML side, then XMLBeans at Apache would be
> > better.
> >
> > JB
> >
> >
> >> -----Original Message-----
> >> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> >> Sent: Friday, August 31, 2007 9:12 PM
> >> To: users@tapestry.apache.org
> >> Subject: T5: POJO to xml lib
> >>
> >>
> >> 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#a12436353
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-POJO-to-xml-lib-tf4363192.html#a12437499
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: T5: POJO to xml lib

Posted by Jonathan Barker <jo...@gmail.com>.

The castor jar was a little over 1 Meg at last track. (There are different
Castor jars - that is for the XML only jar).

A mapping file is not required. There is a default behavior without any
mapping.  I always use a mapping file because I like having control over my
XML.


> -----Original Message-----
> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> Sent: Saturday, September 01, 2007 1:07 AM
> To: users@tapestry.apache.org
> Subject: RE: T5: POJO to xml lib
> 
> 
> Hi Jonathan,
> 
> I tried XStream as suggested by 蝈蝈龙, it works, but library size is big
> around 5mb added, how big is the Castor? one nice thing about XSream is, I
> don't have to write any xml mapping, same with Castore? Thanks.
> 
> A.C.
> 
> Jonathan Barker wrote:
> >
> >
> > Try Castor at www.castor.org
> >
> > It's a Java <-> XML tool that favors the Java side.  It's easy by
> default,
> > but can be very flexible. I use this the most.
> >
> > If you want to favor the XML side, then XMLBeans at Apache would be
> > better.
> >
> > JB
> >
> >
> >> -----Original Message-----
> >> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> >> Sent: Friday, August 31, 2007 9:12 PM
> >> To: users@tapestry.apache.org
> >> Subject: T5: POJO to xml lib
> >>
> >>
> >> 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#a12436353
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/T5%3A-POJO-to-xml-lib-
> tf4363192.html#a12437499
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: POJO to xml lib

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Jonathan,

I tried XStream as suggested by 蝈蝈龙, it works, but library size is big
around 5mb added, how big is the Castor? one nice thing about XSream is, I
don't have to write any xml mapping, same with Castore? Thanks.

A.C.

Jonathan Barker wrote:
> 
> 
> Try Castor at www.castor.org
> 
> It's a Java <-> XML tool that favors the Java side.  It's easy by default,
> but can be very flexible. I use this the most.
> 
> If you want to favor the XML side, then XMLBeans at Apache would be
> better.
> 
> JB
> 
> 
>> -----Original Message-----
>> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
>> Sent: Friday, August 31, 2007 9:12 PM
>> To: users@tapestry.apache.org
>> Subject: T5: POJO to xml lib
>> 
>> 
>> 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#a12436353
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-POJO-to-xml-lib-tf4363192.html#a12437499
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: POJO to xml lib

Posted by Jonathan Barker <jo...@gmail.com>.
Try Castor at www.castor.org

It's a Java <-> XML tool that favors the Java side.  It's easy by default,
but can be very flexible. I use this the most.

If you want to favor the XML side, then XMLBeans at Apache would be better.

JB


> -----Original Message-----
> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> Sent: Friday, August 31, 2007 9:12 PM
> To: users@tapestry.apache.org
> Subject: T5: POJO to xml lib
> 
> 
> 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#a12436353
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi 蝈蝈龙,

I tried XStream's toXML, it works, but not yet try writing to a file. one
thing I notice is, the size of lib, the war file's size was increased from
1.9mb to 7mb, looks like XStream is larger than Tapestry's lib, right?



蝈蝈龙 wrote:
> 
> is XStream good idea?
> 
> 2007/9/1, Fidel Chavarria <fi...@gmail.com>:
>>
>>
>>
>>
>> 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#a12436405
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-POJO-to-xml-lib-tf4363192.html#a12437492
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by 蝈蝈龙 <el...@gmail.com>.
is XStream good idea?

2007/9/1, Fidel Chavarria <fi...@gmail.com>:
>
>
>
>
> 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#a12436405
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: POJO to xml lib

Posted by Fidel Chavarria <fi...@gmail.com>.
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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by Angelo Chen <an...@yahoo.com.hk>.
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#a12436506
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: POJO to xml lib

Posted by Fidel Chavarria <fi...@gmail.com>.


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#a12436405
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org