Re: [Simple-support] Problem serialzing object with lists
Brought to you by:
niallg
|
From: Frank B. <f_b...@ya...> - 2007-08-21 07:03:41
|
Hi Niall,=0A=0ATried it with the @Root annotation in both classes and am st=
ill getting the same error?=0A(btw when i tried to test it with the classes=
as shown in the tutorial (Task, Example, DividerTask ...)=0Ai also got tha=
t message.=0AHas something gone wrong in the last version???=0A=0Athanks=0A=
=0AFrank=0A=0A----- Original Message ----=0AFrom: Niall Gallagher <gallaghe=
r_...@ya...>=0ATo: Frank Beullens <f_b...@ya...>; simple-supp=
or...@li...=0ASent: Monday, August 20, 2007 3:11:06 PM=0ASubj=
ect: Re: [Simple-support] Problem serialzing object with lists=0A=0A=0AHi,=
=0A=0AYou are missing a @Root annotation on the TestPref1=0Aand TestPref2 c=
lasses. The general rule is, if there=0Ais no @Root annotation then a trans=
formation is=0Aattempted as a last resort. However, typically=0Atransformat=
ions will be reserved for simple types,=0Asuch as integers, booleans, strin=
gs, dates, and so on.=0A=0ANiall=0A=0A--- Frank Beullens <f_beullens@yahoo.=
com> wrote:=0A=0A> Hi,=0A> =0A> i have created the following objects:=0A> =
=0A> public interface IPreference {=0A> =0A> }=0A> =0A> public class Te=
stPref1 implements IPreference {=0A> @Element(name=3D"id")=0A> priv=
ate long id =3D 0;=0A> =0A> @Element(name=3D"pref1name")=0A> pr=
ivate String name =3D "";=0A> =0A> /** Creates a new instance of Te=
stPref1 */=0A> public TestPref1() {=0A> }=0A> public long getId=
() {=0A> return id;=0A> }=0A> public void setId(long id) {=
=0A> this.id =3D id;=0A> }=0A> public String getName() {=0A=
> return name;=0A> }=0A> public void setName(String name) {=
=0A> this.name =3D name;=0A> }=0A> =0A> }=0A> =0A> public c=
lass TestPref2 implements IPreference {=0A> @Element(name=3D"pref2code"=
)=0A> private String code =3D "";=0A> =0A> /** Creates a new in=
stance of TestPref2 */=0A> public TestPref2() {=0A> }=0A> publi=
c String getCode() {=0A> return code;=0A> }=0A> public void=
setCode(String code) {=0A> this.code =3D code;=0A> }=0A> =
=0A> }=0A> =0A> @Root(name=3D"preferencegroup")=0A> public class Preference=
Group implements IPreference=0A> {=0A> @ElementList(name=3D"preferences=
")=0A> private List<IPreference> preferences =3D null;=0A> =0A> =
@Attribute(name=3D"groupcode")=0A> private String groupCode =3D "";=0A=
> =0A> public List<IPreference> getPreferences() {=0A> retu=
rn this.preferences;=0A> }=0A> =0A> public void setPreferences(=
List<IPreference>=0A> preferences) {=0A> this.preferences =3D prefe=
rences;=0A> }=0A> public String getGroupCode() {=0A> return=
groupCode;=0A> }=0A> public void setGroupCode(String groupCode) {=
=0A> this.groupCode =3D groupCode;=0A> }=0A> }=0A> =0A> =0A> wh=
en trying to do the following:=0A> =0A> PreferenceGroup group =3D n=
ew=0A> PreferenceGroup();=0A> group.setGroupCode("TESTGROUP");=0A> =
List<IPreference> preferences =3D new=0A> ArrayList<IPreference>();=
=0A> TestPref1 pref1 =3D new TestPref1();=0A> pref1.setId(1=
);=0A> pref1.setName("test preference 1");=0A> preferences.=
add(pref1);=0A> TestPref2 pref2 =3D new TestPref2();=0A> pr=
ef2.setCode("TSTPRF2");=0A> preferences.add(pref2);=0A> gro=
up.setPreferences(preferences);=0A> Serializer serializer =3D new P=
ersister();=0A> File result =3D new File("preferences.xml");=0A> =
try {=0A> serializer.write(group, result);=0A> } =
catch (Exception ex) {=0A> ex.printStackTrace();=0A> }=
=0A> =0A> I get the error:=0A> =0A>=0Aorg.simpleframework.xml.transform.Tra=
nsformException:=0A> Transform of class=0A> com.libesoft.rcp.preferences.te=
st.TestPref1 not=0A> supported=0A> at=0A>=0Aorg.simpleframework.xml=
.transform.PackageMatcher.match(PackageMatcher.java:88)=0A> at=0A>=
=0Aorg.simpleframework.xml.transform.DefaultMatcher.matchType(DefaultMatche=
r.java:111)=0A> at=0A>=0Aorg.simpleframework.xml.transform.DefaultM=
atcher.match(DefaultMatcher.java:90)=0A> at=0A>=0Aorg.simpleframewo=
rk.xml.transform.Transformer.write(Transformer.java:129)=0A> at=0A>=
=0Aorg.simpleframework.xml.load.PrimitiveFactory.getText(PrimitiveFactory.j=
ava:128)=0A> at=0A>=0Aorg.simpleframework.xml.load.Primitive.write(=
Primitive.java:200)=0A> at=0A>=0Aorg.simpleframework.xml.load.Primi=
tiveList.write(PrimitiveList.java:157)=0A> at=0A>=0Aorg.simpleframe=
work.xml.load.Composite.writeElement(Composite.java:589)=0A> at=0A>=
=0Aorg.simpleframework.xml.load.Composite.writeElements(Composite.java:485)=
=0A> at=0A>=0Aorg.simpleframework.xml.load.Composite.write(Composit=
e.java:423)=0A> at=0A>=0Aorg.simpleframework.xml.load.Composite.wri=
te(Composite.java:401)=0A> at=0A>=0Aorg.simpleframework.xml.load.Tr=
averser.write(Traverser.java:186)=0A> at=0A>=0Aorg.simpleframework.=
xml.load.Traverser.write(Traverser.java:165)=0A> at=0A>=0Aorg.simpl=
eframework.xml.load.Traverser.write(Traverser.java:143)=0A> at=0A>=
=0Aorg.simpleframework.xml.load.Persister.write(Persister.java:608)=0A> =
at=0A>=0Aorg.simpleframework.xml.load.Persister.write(Persister.java:5=
90)=0A> at=0A>=0Aorg.simpleframework.xml.load.Persister.write(Persi=
ster.java:571)=0A> at=0A>=0Aorg.simpleframework.xml.load.Persister.=
write(Persister.java:687)=0A> at=0A>=0Aorg.simpleframework.xml.load=
.Persister.write(Persister.java:669)=0A> at=0A>=0Aorg.simpleframewo=
rk.xml.load.Persister.write(Persister.java:650)=0A> at=0A>=0Aorg.si=
mpleframework.xml.load.Persister.write(Persister.java:629)=0A> =0A> =0A> An=
y ideas what i am doing wrong????=0A> =0A> Thanks=0A> =0A> Frank=0A> =0A>=
=0A------------------------------------------------------------------------=
-=0A> This SF.net email is sponsored by: Splunk Inc.=0A> Still grepping thr=
ough log files to find problems? =0A> Stop.=0A> Now Search log events and c=
onfiguration files using=0A> AJAX and a browser.=0A> Download your FREE cop=
y of Splunk now >> =0A> http://get.splunk.com/=0A> ________________________=
_______________________=0A> Simple-support mailing list=0A> Simple-support@=
lists.sourceforge.net=0A>=0Ahttps://lists.sourceforge.net/lists/listinfo/si=
mple-support=0A> =0A=0A=0A=0A =0A____________________________________=
________________________________________________=0ABoardwalk for $500? In 2=
007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Y=
ahoo! Games.=0Ahttp://get.games.yahoo.com/proddesc?gamekey=3Dmonopolyhereno=
w
|