simple-support Mailing List for Simple (Page 74)
Brought to you by:
niallg
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
(2) |
Mar
(2) |
Apr
(13) |
May
(13) |
Jun
(27) |
Jul
(4) |
Aug
(14) |
Sep
(7) |
Oct
|
Nov
(6) |
Dec
(24) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
|
Feb
(21) |
Mar
(10) |
Apr
(15) |
May
(24) |
Jun
(24) |
Jul
(30) |
Aug
(5) |
Sep
(19) |
Oct
(27) |
Nov
(16) |
Dec
(24) |
| 2009 |
Jan
(34) |
Feb
(24) |
Mar
(35) |
Apr
(26) |
May
(8) |
Jun
(17) |
Jul
(28) |
Aug
(31) |
Sep
(36) |
Oct
(35) |
Nov
(20) |
Dec
(16) |
| 2010 |
Jan
(40) |
Feb
(21) |
Mar
(47) |
Apr
(45) |
May
(34) |
Jun
(68) |
Jul
(46) |
Aug
(39) |
Sep
(47) |
Oct
(20) |
Nov
(42) |
Dec
(13) |
| 2011 |
Jan
(41) |
Feb
(16) |
Mar
(32) |
Apr
(44) |
May
(28) |
Jun
(35) |
Jul
(37) |
Aug
(33) |
Sep
(60) |
Oct
(20) |
Nov
(35) |
Dec
(23) |
| 2012 |
Jan
(34) |
Feb
(23) |
Mar
(34) |
Apr
(21) |
May
(48) |
Jun
(24) |
Jul
(31) |
Aug
(39) |
Sep
(25) |
Oct
(10) |
Nov
(27) |
Dec
(28) |
| 2013 |
Jan
(32) |
Feb
(24) |
Mar
(24) |
Apr
(9) |
May
(4) |
Jun
(6) |
Jul
(2) |
Aug
(5) |
Sep
|
Oct
(5) |
Nov
(1) |
Dec
(12) |
| 2014 |
Jan
(14) |
Feb
(16) |
Mar
(5) |
Apr
(3) |
May
(2) |
Jun
(8) |
Jul
(2) |
Aug
|
Sep
(6) |
Oct
|
Nov
(6) |
Dec
|
| 2015 |
Jan
(3) |
Feb
(15) |
Mar
(7) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
(1) |
| 2016 |
Jan
|
Feb
(6) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Quirino Z. <qu...@la...> - 2008-07-10 16:36:11
|
I'm trying to find a solution, but I can't get out of it for now. I toke a look at Simple serialization mechanism: maybe I lost some steps, but the key is: 1) I use persister.write(annotatedObject, anOutputStream,etc) 2) Persister calls Traverser which should be the root of all serialization operations 3) Traverser gets source-object's class and starts scanning process to find annotations and whatever Now, if JBoss drops annotations during class loading, it's impossible for Simple to find them. Anyway we could reload the class with a custom classloader and make Simple use the loaded Class object as annotation scanning map. So my question is: Is it possible to tell Persister to do something like write(Object source, Class reloadedClass, OutputStream stream) ? Thanks in advance -- Quirino Zagarese LaszloItalia Founder (www.laszloitalia.org) Software Development Manager - Galilaeus s.r.l. (www.galilaeus.net) |
|
From: Quirino Z. <qu...@la...> - 2008-07-10 11:35:37
|
Hi,
I'm trying to use Simple in J2EE context (JBoss).
When I try to serialize a class like:
@Root(name="vehicle")
public class Vehicle{
@Attribute(name="model")
private String name;
....
....
}
I obtain only <vehicle/>
This is because JBoss drops all non-J2EE annotations and Simple cannot find
the markers it needs.
Does anybody know any workaround for that?
Thanks in advance
Regards
--
Quirino Zagarese
LaszloItalia Founder (www.laszloitalia.org)
Software Development Manager - Galilaeus s.r.l. (www.galilaeus.net)
|
|
From: Niall G. <gal...@ya...> - 2008-06-27 19:55:44
|
Hi,
It just happens that the default name for a value that has given no @Root is "value". The value is serialized as an independent component, your key which is a primitive serializes as an attribute of the entry. Glad it works for you now.
Niall
--- On Thu, 6/26/08, Micah Jaffe <mi...@af...> wrote:
> From: Micah Jaffe <mi...@af...>
> Subject: Re: [Simple-support] ElementMap question
> To: gal...@ya...
> Cc: sim...@li...
> Date: Thursday, June 26, 2008, 11:57 AM
> Thanks for responding! So I stumbled on a solution nearly
> the same as
> what you suggested. In my below example, I separated out
> the value of
> the text into a value tag just as you suggested, but kept
> everything
> else the same. And the code suddenly started working (for
> reasons I
> don't understand). I didn't have to create a list
> to put values into
> a map. This was my new XML, code is still the same:
>
> <foo level="0">
> <value attr1="abc">value1</value>
> </foo>
> <foo level="1">
> <value attr2="xyz">value2</value>
> </foo>
> <foo level="3">
> <value attr1="123">value3</value>
> </foo>
>
> What is confusing to me on why this is working is I
> didn't create an
> annotation to look for the tag "value". Does
> ElementMap do some
> shortcutting to look for "value" tags for you?
>
> -Micah
>
> On Jun 24, 2008, at 10:16 AM, Niall Gallagher wrote:
>
> > Hi,
> >
> > Have a look at the Dictionary class in
> org.simpleframework.xml.util.
> > This looks like what you want. In order to use
> attributes in the
> > value it has to be a sub-element of the entry and can
> not go in the
> > entry element. For example:
> >
> > <entry key="key>
> > <value a="a" b="b"
> c="c"/>
> > </entry>
> >
> > In order to get a flat list you will need to use an
> ElementList. The
> > Dictionary (which is a HashSet) object can make use of
> an attribute
> > to do this. It has a get() method. If you want you can
> use an
> > ElementList and transfer this via some key to a map
> using the
> > @Commit annotation like so.
> >
> >
> > public class MyClass {
> >
> > @ElementList(inline=true)
> > private List<Foo> list;
> > private Map<Integer, Foo> map;
> >
> > @Commit
> > private void commit() {
> > for(Foo foo : list) {
> > map.put(foo.level, foo);
> > }
> > }
> > }
> >
> > Hope this helps.
> >
> > Niall
> >
> >
> > --- On Mon, 6/23/08, Micah Jaffe
> <mi...@af...> wrote:
> >
> >> From: Micah Jaffe
> <mi...@af...>
> >> Subject: [Simple-support] ElementMap question
> >> To: sim...@li...
> >> Date: Monday, June 23, 2008, 2:37 PM
> >> I have an ElementMap that I'm declaring as
> such:
> >>
> >> @ElementMap(entry="foo",
> key="level",
> >> attribute=true, inline=true)
> >> private HashMap<Integer, Foo> map = new
> >> HashMap<Integer, Foo>();
> >>
> >> private static class Foo
> >> {
> >> @Attribute(required=false)
> >> private String attr1;
> >>
> >> @Attribute(required=false)
> >> private String attr2;
> >>
> >> @Text
> >> private String value;
> >> }
> >>
> >> The goal would be to be able to read XML like
> this:
> >>
> >> <foo level="0"
> >> attr1="abc">value1</foo>
> >> <foo level="1"
> >> attr2="xyz">value2</foo>
> >> <foo level="3"
> >> attr1="123">value3</foo>
> >>
> >> When testing the code it seems to pull out the key
> >> information
> >> correctly, but is setting every value of Foo in
> the HashMap
> >> to null.
> >> The goal is to be able to retrieve an object from
> this map
> >> that will
> >> always be keyed off "level", and have N
> number of
> >> attributes (meta
> >> data) which are optional, and only a single value.
> >>
> >> What am I doing wrong?
> >>
> >> -Micah
> >>
> >>
> -------------------------------------------------------------------------
> >> Check out the new SourceForge.net Marketplace.
> >> It's the best place to buy or sell services
> for
> >> just about anything Open Source.
> >> http://sourceforge.net/services/buy/index.php
> >> _______________________________________________
> >> Simple-support mailing list
> >> Sim...@li...
> >>
> https://lists.sourceforge.net/lists/listinfo/simple-support
> >
> >
> >
|
|
From: Micah J. <mi...@af...> - 2008-06-26 18:57:51
|
Thanks for responding! So I stumbled on a solution nearly the same as
what you suggested. In my below example, I separated out the value of
the text into a value tag just as you suggested, but kept everything
else the same. And the code suddenly started working (for reasons I
don't understand). I didn't have to create a list to put values into
a map. This was my new XML, code is still the same:
<foo level="0">
<value attr1="abc">value1</value>
</foo>
<foo level="1">
<value attr2="xyz">value2</value>
</foo>
<foo level="3">
<value attr1="123">value3</value>
</foo>
What is confusing to me on why this is working is I didn't create an
annotation to look for the tag "value". Does ElementMap do some
shortcutting to look for "value" tags for you?
-Micah
On Jun 24, 2008, at 10:16 AM, Niall Gallagher wrote:
> Hi,
>
> Have a look at the Dictionary class in org.simpleframework.xml.util.
> This looks like what you want. In order to use attributes in the
> value it has to be a sub-element of the entry and can not go in the
> entry element. For example:
>
> <entry key="key>
> <value a="a" b="b" c="c"/>
> </entry>
>
> In order to get a flat list you will need to use an ElementList. The
> Dictionary (which is a HashSet) object can make use of an attribute
> to do this. It has a get() method. If you want you can use an
> ElementList and transfer this via some key to a map using the
> @Commit annotation like so.
>
>
> public class MyClass {
>
> @ElementList(inline=true)
> private List<Foo> list;
> private Map<Integer, Foo> map;
>
> @Commit
> private void commit() {
> for(Foo foo : list) {
> map.put(foo.level, foo);
> }
> }
> }
>
> Hope this helps.
>
> Niall
>
>
> --- On Mon, 6/23/08, Micah Jaffe <mi...@af...> wrote:
>
>> From: Micah Jaffe <mi...@af...>
>> Subject: [Simple-support] ElementMap question
>> To: sim...@li...
>> Date: Monday, June 23, 2008, 2:37 PM
>> I have an ElementMap that I'm declaring as such:
>>
>> @ElementMap(entry="foo", key="level",
>> attribute=true, inline=true)
>> private HashMap<Integer, Foo> map = new
>> HashMap<Integer, Foo>();
>>
>> private static class Foo
>> {
>> @Attribute(required=false)
>> private String attr1;
>>
>> @Attribute(required=false)
>> private String attr2;
>>
>> @Text
>> private String value;
>> }
>>
>> The goal would be to be able to read XML like this:
>>
>> <foo level="0"
>> attr1="abc">value1</foo>
>> <foo level="1"
>> attr2="xyz">value2</foo>
>> <foo level="3"
>> attr1="123">value3</foo>
>>
>> When testing the code it seems to pull out the key
>> information
>> correctly, but is setting every value of Foo in the HashMap
>> to null.
>> The goal is to be able to retrieve an object from this map
>> that will
>> always be keyed off "level", and have N number of
>> attributes (meta
>> data) which are optional, and only a single value.
>>
>> What am I doing wrong?
>>
>> -Micah
>>
>> -------------------------------------------------------------------------
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services for
>> just about anything Open Source.
>> http://sourceforge.net/services/buy/index.php
>> _______________________________________________
>> Simple-support mailing list
>> Sim...@li...
>> https://lists.sourceforge.net/lists/listinfo/simple-support
>
>
>
|
|
From: Niall G. <gal...@ya...> - 2008-06-24 17:16:26
|
Hi,
Have a look at the Dictionary class in org.simpleframework.xml.util. This looks like what you want. In order to use attributes in the value it has to be a sub-element of the entry and can not go in the entry element. For example:
<entry key="key>
<value a="a" b="b" c="c"/>
</entry>
In order to get a flat list you will need to use an ElementList. The Dictionary (which is a HashSet) object can make use of an attribute to do this. It has a get() method. If you want you can use an ElementList and transfer this via some key to a map using the @Commit annotation like so.
public class MyClass {
@ElementList(inline=true)
private List<Foo> list;
private Map<Integer, Foo> map;
@Commit
private void commit() {
for(Foo foo : list) {
map.put(foo.level, foo);
}
}
}
Hope this helps.
Niall
--- On Mon, 6/23/08, Micah Jaffe <mi...@af...> wrote:
> From: Micah Jaffe <mi...@af...>
> Subject: [Simple-support] ElementMap question
> To: sim...@li...
> Date: Monday, June 23, 2008, 2:37 PM
> I have an ElementMap that I'm declaring as such:
>
> @ElementMap(entry="foo", key="level",
> attribute=true, inline=true)
> private HashMap<Integer, Foo> map = new
> HashMap<Integer, Foo>();
>
> private static class Foo
> {
> @Attribute(required=false)
> private String attr1;
>
> @Attribute(required=false)
> private String attr2;
>
> @Text
> private String value;
> }
>
> The goal would be to be able to read XML like this:
>
> <foo level="0"
> attr1="abc">value1</foo>
> <foo level="1"
> attr2="xyz">value2</foo>
> <foo level="3"
> attr1="123">value3</foo>
>
> When testing the code it seems to pull out the key
> information
> correctly, but is setting every value of Foo in the HashMap
> to null.
> The goal is to be able to retrieve an object from this map
> that will
> always be keyed off "level", and have N number of
> attributes (meta
> data) which are optional, and only a single value.
>
> What am I doing wrong?
>
> -Micah
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|
|
From: Micah J. <mi...@af...> - 2008-06-23 21:37:56
|
I have an ElementMap that I'm declaring as such:
@ElementMap(entry="foo", key="level", attribute=true, inline=true)
private HashMap<Integer, Foo> map = new HashMap<Integer, Foo>();
private static class Foo
{
@Attribute(required=false)
private String attr1;
@Attribute(required=false)
private String attr2;
@Text
private String value;
}
The goal would be to be able to read XML like this:
<foo level="0" attr1="abc">value1</foo>
<foo level="1" attr2="xyz">value2</foo>
<foo level="3" attr1="123">value3</foo>
When testing the code it seems to pull out the key information
correctly, but is setting every value of Foo in the HashMap to null.
The goal is to be able to retrieve an object from this map that will
always be keyed off "level", and have N number of attributes (meta
data) which are optional, and only a single value.
What am I doing wrong?
-Micah
|
|
From: Niall G. <gal...@ya...> - 2008-06-15 11:36:37
|
Hi,
With regard to why I have kept the default strategy private, I am intending on writing an additional package to make it easy to write strategies. This would make it easier to modify the generated XML as it is being serialized and deserialized. I hope to get around to this shortly.
Niall
--- On Fri, 6/13/08, Graham Stewart <gr...@mo...> wrote:
> From: Graham Stewart <gr...@mo...>
> Subject: Re: [Simple-support] Beginner Question
> To: gal...@ya...
> Cc: "Timo Rumland" <cr...@ol...>, sim...@li...
> Date: Friday, June 13, 2008, 4:13 PM
> Thanks Niall,
>
> That worked well.
>
> Unfortunately the DefaultStrategy references a number of
> non-public
> classes so i started out having to copy things like
> ArrayType and
> ClassType into my own project space.
>
> In the end I went ahead and changed DefaultStrategy to be a
> public
> class so I could make my custom Strategy extend it. This
> makes my own
> project code much neater at the expense of having a custom
> version of
> the simple jar.
>
> Is there a rationale for keeping DefaultStrategy private?
>
> regards,
> Graham
>
>
>
> On Thu, Jun 12, 2008 at 11:25 AM, Niall Gallagher
> <gal...@ya...> wrote:
> > Hi,
> >
> > Well the issue exists only for the root class. The
> root element does not use the class attribute by default.
> So if you had:
> >
> > @Blah
> > public class Blah {
> > @Element
> > private TaskInterface task;
> > }
> >
> > Then serialization would have:
> >
> > <blah>
> > <task class="com.package.MyTask"
> etc.....>
> > etc....
> > </task>
> > </blah>
> >
> > However because you want the root element to contain
> the class here is what you can do. If you have the source
> code to simple, which is available in the download you will
> see the DefaultStrategy.java object in the package
> org/simpleframework/http/load package. You need to take
> this source code to build your own strategy. In your
> strategy you would re-implement the setRoot method to look
> like this.
> >
> > public boolean setElement(Class field, Object value,
> NodeMap node, Map map){
> > boolean result = setElement(field, value node,
> map);
> >
> > node.put(label, value.getClass().getName());
> > return result;
> > }
> >
> > This will ensure that each time you write an object,
> the root element will always use the class= attribute. Or
> course you can be more intelligent than this, and decide
> when you want the class= attribute and when you do not.
> >
> > Hope this helps,
> > Niall
> >
> > --- On Tue, 6/10/08, Graham Stewart
> <gr...@mo...> wrote:
> >
> >> From: Graham Stewart
> <gr...@mo...>
> >> Subject: Re: [Simple-support] Beginner Question
> >> To: "Timo Rumland"
> <cr...@ol...>
> >> Cc: sim...@li...
> >> Date: Tuesday, June 10, 2008, 4:43 PM
> >> On Tue, Jun 10, 2008 at 3:59 PM, Timo Rumland
> >> <cr...@ol...> wrote:
> >> > Hello Graham,
> >> >
> >> >> But if I omit the class attribute then
> this:
> >> >
> >> >> TaskInterface o =
> >> serializer.read(TaskInterface.class,
> "<task1
> >> >> a=\"14\"
> >> b=\"13\"/>>");
> >> >> will fail with
> >> >
> >> > you want to get a TaskInterface, which is
> apparently
> >> an interface,
> >> > returned by the serializer. This is possible
> only if
> >> the serializer
> >> > knows what implementation to instantiate. If
> you have
> >> no "class"
> >> > parameter in the XML, how can the serializer
> know
> >> which class to
> >> > instantiate (you can't instantiate an
> interface)?
> >>
> >> Right, i entirely expect to have to provide the
> class
> >> attribute when
> >> i'm deserializing to an interface.
> >>
> >> How do i get the serializer to put it there?
> >>
> >> If i have
> >>
> >> TaskInterface myTask = new Task1(14,13);
> >> myPersister.write(myTask, "output.xml");
> >>
> >> then it writes out the xml without the class
> attribute, so
> >> I end up with:
> >>
> >> <task1 a="14" b="13"/>
> >>
> >> instead of what I really want, which is:
> >>
> >> <task1
> class="com.company.om.tasks.Task1"
> >> a="14" b="13"/>
> >>
> >>
> >> Does that make sense?
> >> How do I get Persister.write() to include the
> class
> >> attribute?
> >>
> >>
> >> thanks again,
> >> Graham
> >>
> >>
> -------------------------------------------------------------------------
> >> Check out the new SourceForge.net Marketplace.
> >> It's the best place to buy or sell services
> for
> >> just about anything Open Source.
> >> http://sourceforge.net/services/buy/index.php
> >> _______________________________________________
> >> Simple-support mailing list
> >> Sim...@li...
> >>
> https://lists.sourceforge.net/lists/listinfo/simple-support
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
|
|
From: Graham S. <gr...@mo...> - 2008-06-13 23:13:11
|
Thanks Niall,
That worked well.
Unfortunately the DefaultStrategy references a number of non-public
classes so i started out having to copy things like ArrayType and
ClassType into my own project space.
In the end I went ahead and changed DefaultStrategy to be a public
class so I could make my custom Strategy extend it. This makes my own
project code much neater at the expense of having a custom version of
the simple jar.
Is there a rationale for keeping DefaultStrategy private?
regards,
Graham
On Thu, Jun 12, 2008 at 11:25 AM, Niall Gallagher
<gal...@ya...> wrote:
> Hi,
>
> Well the issue exists only for the root class. The root element does not use the class attribute by default. So if you had:
>
> @Blah
> public class Blah {
> @Element
> private TaskInterface task;
> }
>
> Then serialization would have:
>
> <blah>
> <task class="com.package.MyTask" etc.....>
> etc....
> </task>
> </blah>
>
> However because you want the root element to contain the class here is what you can do. If you have the source code to simple, which is available in the download you will see the DefaultStrategy.java object in the package org/simpleframework/http/load package. You need to take this source code to build your own strategy. In your strategy you would re-implement the setRoot method to look like this.
>
> public boolean setElement(Class field, Object value, NodeMap node, Map map){
> boolean result = setElement(field, value node, map);
>
> node.put(label, value.getClass().getName());
> return result;
> }
>
> This will ensure that each time you write an object, the root element will always use the class= attribute. Or course you can be more intelligent than this, and decide when you want the class= attribute and when you do not.
>
> Hope this helps,
> Niall
>
> --- On Tue, 6/10/08, Graham Stewart <gr...@mo...> wrote:
>
>> From: Graham Stewart <gr...@mo...>
>> Subject: Re: [Simple-support] Beginner Question
>> To: "Timo Rumland" <cr...@ol...>
>> Cc: sim...@li...
>> Date: Tuesday, June 10, 2008, 4:43 PM
>> On Tue, Jun 10, 2008 at 3:59 PM, Timo Rumland
>> <cr...@ol...> wrote:
>> > Hello Graham,
>> >
>> >> But if I omit the class attribute then this:
>> >
>> >> TaskInterface o =
>> serializer.read(TaskInterface.class, "<task1
>> >> a=\"14\"
>> b=\"13\"/>>");
>> >> will fail with
>> >
>> > you want to get a TaskInterface, which is apparently
>> an interface,
>> > returned by the serializer. This is possible only if
>> the serializer
>> > knows what implementation to instantiate. If you have
>> no "class"
>> > parameter in the XML, how can the serializer know
>> which class to
>> > instantiate (you can't instantiate an interface)?
>>
>> Right, i entirely expect to have to provide the class
>> attribute when
>> i'm deserializing to an interface.
>>
>> How do i get the serializer to put it there?
>>
>> If i have
>>
>> TaskInterface myTask = new Task1(14,13);
>> myPersister.write(myTask, "output.xml");
>>
>> then it writes out the xml without the class attribute, so
>> I end up with:
>>
>> <task1 a="14" b="13"/>
>>
>> instead of what I really want, which is:
>>
>> <task1 class="com.company.om.tasks.Task1"
>> a="14" b="13"/>
>>
>>
>> Does that make sense?
>> How do I get Persister.write() to include the class
>> attribute?
>>
>>
>> thanks again,
>> Graham
>>
>> -------------------------------------------------------------------------
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services for
>> just about anything Open Source.
>> http://sourceforge.net/services/buy/index.php
>> _______________________________________________
>> Simple-support mailing list
>> Sim...@li...
>> https://lists.sourceforge.net/lists/listinfo/simple-support
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
|
|
From: Niall G. <gal...@ya...> - 2008-06-12 17:25:57
|
Hi,
Well the issue exists only for the root class. The root element does not use the class attribute by default. So if you had:
@Blah
public class Blah {
@Element
private TaskInterface task;
}
Then serialization would have:
<blah>
<task class="com.package.MyTask" etc.....>
etc....
</task>
</blah>
However because you want the root element to contain the class here is what you can do. If you have the source code to simple, which is available in the download you will see the DefaultStrategy.java object in the package org/simpleframework/http/load package. You need to take this source code to build your own strategy. In your strategy you would re-implement the setRoot method to look like this.
public boolean setElement(Class field, Object value, NodeMap node, Map map){
boolean result = setElement(field, value node, map);
node.put(label, value.getClass().getName());
return result;
}
This will ensure that each time you write an object, the root element will always use the class= attribute. Or course you can be more intelligent than this, and decide when you want the class= attribute and when you do not.
Hope this helps,
Niall
--- On Tue, 6/10/08, Graham Stewart <gr...@mo...> wrote:
> From: Graham Stewart <gr...@mo...>
> Subject: Re: [Simple-support] Beginner Question
> To: "Timo Rumland" <cr...@ol...>
> Cc: sim...@li...
> Date: Tuesday, June 10, 2008, 4:43 PM
> On Tue, Jun 10, 2008 at 3:59 PM, Timo Rumland
> <cr...@ol...> wrote:
> > Hello Graham,
> >
> >> But if I omit the class attribute then this:
> >
> >> TaskInterface o =
> serializer.read(TaskInterface.class, "<task1
> >> a=\"14\"
> b=\"13\"/>>");
> >> will fail with
> >
> > you want to get a TaskInterface, which is apparently
> an interface,
> > returned by the serializer. This is possible only if
> the serializer
> > knows what implementation to instantiate. If you have
> no "class"
> > parameter in the XML, how can the serializer know
> which class to
> > instantiate (you can't instantiate an interface)?
>
> Right, i entirely expect to have to provide the class
> attribute when
> i'm deserializing to an interface.
>
> How do i get the serializer to put it there?
>
> If i have
>
> TaskInterface myTask = new Task1(14,13);
> myPersister.write(myTask, "output.xml");
>
> then it writes out the xml without the class attribute, so
> I end up with:
>
> <task1 a="14" b="13"/>
>
> instead of what I really want, which is:
>
> <task1 class="com.company.om.tasks.Task1"
> a="14" b="13"/>
>
>
> Does that make sense?
> How do I get Persister.write() to include the class
> attribute?
>
>
> thanks again,
> Graham
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|
|
From: Graham S. <gr...@mo...> - 2008-06-10 23:43:38
|
On Tue, Jun 10, 2008 at 3:59 PM, Timo Rumland <cr...@ol...> wrote: > Hello Graham, > >> But if I omit the class attribute then this: > >> TaskInterface o = serializer.read(TaskInterface.class, "<task1 >> a=\"14\" b=\"13\"/>>"); >> will fail with > > you want to get a TaskInterface, which is apparently an interface, > returned by the serializer. This is possible only if the serializer > knows what implementation to instantiate. If you have no "class" > parameter in the XML, how can the serializer know which class to > instantiate (you can't instantiate an interface)? Right, i entirely expect to have to provide the class attribute when i'm deserializing to an interface. How do i get the serializer to put it there? If i have TaskInterface myTask = new Task1(14,13); myPersister.write(myTask, "output.xml"); then it writes out the xml without the class attribute, so I end up with: <task1 a="14" b="13"/> instead of what I really want, which is: <task1 class="com.company.om.tasks.Task1" a="14" b="13"/> Does that make sense? How do I get Persister.write() to include the class attribute? thanks again, Graham |
|
From: Timo R. <cr...@ol...> - 2008-06-10 21:59:35
|
Hello Graham, > But if I omit the class attribute then this: > TaskInterface o = serializer.read(TaskInterface.class, "<task1 > a=\"14\" b=\"13\"/>>"); > will fail with you want to get a TaskInterface, which is apparently an interface, returned by the serializer. This is possible only if the serializer knows what implementation to instantiate. If you have no "class" parameter in the XML, how can the serializer know which class to instantiate (you can't instantiate an interface)? Regards, Timo |
|
From: Graham S. <gr...@mo...> - 2008-06-10 21:23:31
|
Thanks for the quick reply Niall. Unfortunately it seems that the class attribute is not ignored by the deserializer. This works fine: TaskInterface o = serializer.read(TaskInterface.class, "<task1 class=\"com.company.om.tasks.Task1\" a=\"14\" b=\"13\"/>"); But if I omit the class attribute then this: TaskInterface o = serializer.read(TaskInterface.class, "<task1 a=\"14\" b=\"13\"/>"); will fail with Exception in thread "main" org.simpleframework.xml.load.InstantiationException: Cannot instantiate interface com.company.om.tasks.TaskInterface at org.simpleframework.xml.load.ObjectFactory.getInstance(ObjectFactory.java:67) at org.simpleframework.xml.load.Composite.read(Composite.java:112) at org.simpleframework.xml.load.Traverser.read(Traverser.java:71) at org.simpleframework.xml.load.Persister.read(Persister.java:392) at org.simpleframework.xml.load.Persister.read(Persister.java:374) at org.simpleframework.xml.load.Persister.read(Persister.java:355) at org.simpleframework.xml.load.Persister.read(Persister.java:337) at org.simpleframework.xml.load.Persister.read(Persister.java:258) at com.somispo.processor.main.Main.main(Main.java:69) I think that makes sense. If i've got a number of concrete classes that implement the same interface, how would the deserializer know which one to use without a fully qualified class name in the xml? In any event the real problem I have is getting the serializer to include the classname when i persist the object regards, Graham On Tue, Jun 10, 2008 at 3:01 PM, Niall Gallagher <gal...@ya...> wrote: > Hi, > > The class attribute is a special attribute that is ignored by the deserialization. Can you use object.getClass().getName() ? > > Also you dont need to cast, the following. > > TaskInterface o = (TaskInterface) serializer.read(TaskInterface.class, > serializedText); > > works as: > > TaskInterface o = serializer.read(TaskInterface.class, > serializedText); > > Its casted by the class type TaskInterface.class, the return type is autocasted at compile time. > > Hope this helps, > Niall > > > --- On Tue, 6/10/08, Graham Stewart <gr...@mo...> wrote: > >> From: Graham Stewart <gr...@mo...> >> Subject: [Simple-support] Beginner Question >> To: sim...@li... >> Date: Tuesday, June 10, 2008, 12:36 PM >> First let me say that simple looks great - it's >> refreshing to find a >> java serialization tool that works without 5 megs of >> dependencies! >> >> >> I'm trying to use Simple in a situation very similar to >> this tutorial example >> >> http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#override >> >> I have two classes that implement TaskInterface, Task1 and >> Task2 and >> i'd like to be able to serialize the TaskInterface and >> get usable XML. >> >> Putting the class name in the xml seems to work and both of >> these >> deserialize fine: >> >> <task1 class="com.somispo.om.tasks.Task1" >> a="14" b="13"/> >> <task2 class="com.somispo.om.tasks.Task2" >> c="15" d="16"/> >> >> TaskInterface o = (TaskInterface) >> serializer.read(TaskInterface.class, >> serializedText); >> >> >> What I can't figure out is how to get that class >> attribute in the xml >> output from the Persister? It seems like it should be >> straightforward, >> but I can't get it to show when I try to persist a >> TaskInterface. >> >> thanks, >> Graham >> >> ------------------------------------------------------------------------- >> Check out the new SourceForge.net Marketplace. >> It's the best place to buy or sell services for >> just about anything Open Source. >> http://sourceforge.net/services/buy/index.php >> _______________________________________________ >> Simple-support mailing list >> Sim...@li... >> https://lists.sourceforge.net/lists/listinfo/simple-support > > > > |
|
From: Niall G. <gal...@ya...> - 2008-06-10 21:01:36
|
Hi, The class attribute is a special attribute that is ignored by the deserialization. Can you use object.getClass().getName() ? Also you dont need to cast, the following. TaskInterface o = (TaskInterface) serializer.read(TaskInterface.class, serializedText); works as: TaskInterface o = serializer.read(TaskInterface.class, serializedText); Its casted by the class type TaskInterface.class, the return type is autocasted at compile time. Hope this helps, Niall --- On Tue, 6/10/08, Graham Stewart <gr...@mo...> wrote: > From: Graham Stewart <gr...@mo...> > Subject: [Simple-support] Beginner Question > To: sim...@li... > Date: Tuesday, June 10, 2008, 12:36 PM > First let me say that simple looks great - it's > refreshing to find a > java serialization tool that works without 5 megs of > dependencies! > > > I'm trying to use Simple in a situation very similar to > this tutorial example > > http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#override > > I have two classes that implement TaskInterface, Task1 and > Task2 and > i'd like to be able to serialize the TaskInterface and > get usable XML. > > Putting the class name in the xml seems to work and both of > these > deserialize fine: > > <task1 class="com.somispo.om.tasks.Task1" > a="14" b="13"/> > <task2 class="com.somispo.om.tasks.Task2" > c="15" d="16"/> > > TaskInterface o = (TaskInterface) > serializer.read(TaskInterface.class, > serializedText); > > > What I can't figure out is how to get that class > attribute in the xml > output from the Persister? It seems like it should be > straightforward, > but I can't get it to show when I try to persist a > TaskInterface. > > thanks, > Graham > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support |
|
From: Graham S. <gr...@mo...> - 2008-06-10 19:36:48
|
First let me say that simple looks great - it's refreshing to find a java serialization tool that works without 5 megs of dependencies! I'm trying to use Simple in a situation very similar to this tutorial example http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#override I have two classes that implement TaskInterface, Task1 and Task2 and i'd like to be able to serialize the TaskInterface and get usable XML. Putting the class name in the xml seems to work and both of these deserialize fine: <task1 class="com.somispo.om.tasks.Task1" a="14" b="13"/> <task2 class="com.somispo.om.tasks.Task2" c="15" d="16"/> TaskInterface o = (TaskInterface) serializer.read(TaskInterface.class, serializedText); What I can't figure out is how to get that class attribute in the xml output from the Persister? It seems like it should be straightforward, but I can't get it to show when I try to persist a TaskInterface. thanks, Graham |
|
From: Niall G. <gal...@ya...> - 2008-06-07 10:12:46
|
Hi, This simply means that StaX the XML parser used by simple does not need to be bundled with it in order for it to work with 1.6, for most other XML binding and serialization frameworks you will need quite a few dependancies which make the over all size much higher. Simple has no dependancies in Java 1.6. Niall --- On Fri, 6/6/08, Mark Wyszomierski <ma...@gm...> wrote: > From: Mark Wyszomierski <ma...@gm...> > Subject: Re: [Simple-support] Class type, jar size > To: gal...@ya... > Cc: sim...@li... > Date: Friday, June 6, 2008, 1:02 PM > Hi Niall, > > Thanks for the info. I'll check out the strategy stuff > now. > > As for the java 1.6 stuff, I don't quite understand > what this means. > My applet is linking to the simple jar which is ~180kb. If > the end > user is running java 1.6, does this mean that they > won't have to > 'download' the full 180kb jar, rather they'll > just need parts of it? > If that's the case, is that handled automatically, or > do I need to do > something in order to enable it? > > Thanks, > Mark > > On Fri, Jun 6, 2008 at 2:20 PM, Niall Gallagher > <gal...@ya...> wrote: > > Hi, > > > > Yes there is a way to send the type, the Strategy > object was implemented for just this. If you use the > org.simpleframework.xml.load.DefaultStrategy you can modify > it to send the class= parameter for each type. If you want > to go even further you can implement your own Strategy > perhaps based on the provided DefaultStrategy to send > something other than the class, for instance you could map > the class name to a code, for instance. > > > > com.domain.Person="person" > > com.domain.Address="address" > > > > And so on. As for a stripped down version, there is > none. However if you use Java 1.6 the XML serialization > framework has no dependencies. So no external tool which > many other frameworks require. > > > > Hope this helps > > Niall > > > > --- On Fri, 6/6/08, Mark Wyszomierski > <ma...@gm...> wrote: > > > >> From: Mark Wyszomierski <ma...@gm...> > >> Subject: [Simple-support] Class type, jar size > >> To: sim...@li... > >> Date: Friday, June 6, 2008, 4:12 AM > >> Hi all, > >> > >> I've been looking for a fast lightweight java > xml > >> serializer for a few > >> days, just came across Simple, it looks great. I > especially > >> like the > >> compact xml it can produce, since I'm going to > be using > >> it for string > >> message passing across a network. > >> > >> I'm wondering if there's a quick way to > query the > >> class type > >> serialized in a String, for example, I serialized > a class > >> called > >> Person: > >> > >> <person a="Bob" > b="55"> > >> > >> now I receive that string over the net, and I need > to > >> figure out what > >> kind of class is serialized in it. Is there some > facility > >> in Simple > >> for doing that, or should I prepend some header > myself? > >> > >> Also, the Simple library is ~180k - is there some > stripped > >> down > >> version which makes a smaller jar by any chance? > >> > >> Thanks for the great tool, > >> Mark > >> > >> > ------------------------------------------------------------------------- > >> Check out the new SourceForge.net Marketplace. > >> It's the best place to buy or sell services > for > >> just about anything Open Source. > >> http://sourceforge.net/services/buy/index.php > >> _______________________________________________ > >> Simple-support mailing list > >> Sim...@li... > >> > https://lists.sourceforge.net/lists/listinfo/simple-support > > > > > > > > |
|
From: Niall G. <gal...@ya...> - 2008-06-07 10:09:39
|
Hi,
There are two problems here. Firstly you need to have the inner class as static so that it can be reflectively instantiated. Also, you may have heard that Java generics are not great. This is for a number of reasons, one being that they are not reified which means that for the following
T m_vehichle
T is not available reflectively. The compiler does not maintain the compiled class type. So its simply an Object. Since the serializer has no type information it can not determine how to serialize it.
Niall
--- On Fri, 6/6/08, Mark Wyszomierski <ma...@gm...> wrote:
> From: Mark Wyszomierski <ma...@gm...>
> Subject: [Simple-support] generics
> To: sim...@li...
> Date: Friday, June 6, 2008, 9:27 PM
> Hi,
>
> I'm trying to serialize a class that uses generics
> like:
>
> @Root
> public class Garage<T extends Vehichle>
> {
> @Element
> protected T m_vehichle;
> }
>
> @Root
> public class Vehichle
> {
> @Element
> protected int m_serialNumber;
> }
>
> @Root
> public class Car extends Vehichle
> {
> @Element
> protected int m_numDoors;
> }
>
> Serializing an instance of Garage works ok:
>
> Garage<Car> garage = new Garage<Car>(new
> Car());
> // ...
> serializer.write(garage);
>
> But deserializing throws an exception:
>
> java.lang.NoSuchMethodException:
> TestSimpleXML$Garage.<init>()
>
> Garage<Car> garage = null;
> try {
> garage = serializer.read(Garage.class, xmlString);
>
> Is it not possible to do?
>
> Thanks,
> Mark
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|
|
From: Mark W. <ma...@gm...> - 2008-06-07 04:27:13
|
Hi,
I'm trying to serialize a class that uses generics like:
@Root
public class Garage<T extends Vehichle>
{
@Element
protected T m_vehichle;
}
@Root
public class Vehichle
{
@Element
protected int m_serialNumber;
}
@Root
public class Car extends Vehichle
{
@Element
protected int m_numDoors;
}
Serializing an instance of Garage works ok:
Garage<Car> garage = new Garage<Car>(new Car());
// ...
serializer.write(garage);
But deserializing throws an exception:
java.lang.NoSuchMethodException: TestSimpleXML$Garage.<init>()
Garage<Car> garage = null;
try {
garage = serializer.read(Garage.class, xmlString);
Is it not possible to do?
Thanks,
Mark
|
|
From: Mark W. <ma...@gm...> - 2008-06-06 20:02:16
|
Hi Niall, Thanks for the info. I'll check out the strategy stuff now. As for the java 1.6 stuff, I don't quite understand what this means. My applet is linking to the simple jar which is ~180kb. If the end user is running java 1.6, does this mean that they won't have to 'download' the full 180kb jar, rather they'll just need parts of it? If that's the case, is that handled automatically, or do I need to do something in order to enable it? Thanks, Mark On Fri, Jun 6, 2008 at 2:20 PM, Niall Gallagher <gal...@ya...> wrote: > Hi, > > Yes there is a way to send the type, the Strategy object was implemented for just this. If you use the org.simpleframework.xml.load.DefaultStrategy you can modify it to send the class= parameter for each type. If you want to go even further you can implement your own Strategy perhaps based on the provided DefaultStrategy to send something other than the class, for instance you could map the class name to a code, for instance. > > com.domain.Person="person" > com.domain.Address="address" > > And so on. As for a stripped down version, there is none. However if you use Java 1.6 the XML serialization framework has no dependencies. So no external tool which many other frameworks require. > > Hope this helps > Niall > > --- On Fri, 6/6/08, Mark Wyszomierski <ma...@gm...> wrote: > >> From: Mark Wyszomierski <ma...@gm...> >> Subject: [Simple-support] Class type, jar size >> To: sim...@li... >> Date: Friday, June 6, 2008, 4:12 AM >> Hi all, >> >> I've been looking for a fast lightweight java xml >> serializer for a few >> days, just came across Simple, it looks great. I especially >> like the >> compact xml it can produce, since I'm going to be using >> it for string >> message passing across a network. >> >> I'm wondering if there's a quick way to query the >> class type >> serialized in a String, for example, I serialized a class >> called >> Person: >> >> <person a="Bob" b="55"> >> >> now I receive that string over the net, and I need to >> figure out what >> kind of class is serialized in it. Is there some facility >> in Simple >> for doing that, or should I prepend some header myself? >> >> Also, the Simple library is ~180k - is there some stripped >> down >> version which makes a smaller jar by any chance? >> >> Thanks for the great tool, >> Mark >> >> ------------------------------------------------------------------------- >> Check out the new SourceForge.net Marketplace. >> It's the best place to buy or sell services for >> just about anything Open Source. >> http://sourceforge.net/services/buy/index.php >> _______________________________________________ >> Simple-support mailing list >> Sim...@li... >> https://lists.sourceforge.net/lists/listinfo/simple-support > > > > |
|
From: Niall G. <gal...@ya...> - 2008-06-06 18:21:06
|
Hi, Yes there is a way to send the type, the Strategy object was implemented for just this. If you use the org.simpleframework.xml.load.DefaultStrategy you can modify it to send the class= parameter for each type. If you want to go even further you can implement your own Strategy perhaps based on the provided DefaultStrategy to send something other than the class, for instance you could map the class name to a code, for instance. com.domain.Person="person" com.domain.Address="address" And so on. As for a stripped down version, there is none. However if you use Java 1.6 the XML serialization framework has no dependencies. So no external tool which many other frameworks require. Hope this helps Niall --- On Fri, 6/6/08, Mark Wyszomierski <ma...@gm...> wrote: > From: Mark Wyszomierski <ma...@gm...> > Subject: [Simple-support] Class type, jar size > To: sim...@li... > Date: Friday, June 6, 2008, 4:12 AM > Hi all, > > I've been looking for a fast lightweight java xml > serializer for a few > days, just came across Simple, it looks great. I especially > like the > compact xml it can produce, since I'm going to be using > it for string > message passing across a network. > > I'm wondering if there's a quick way to query the > class type > serialized in a String, for example, I serialized a class > called > Person: > > <person a="Bob" b="55"> > > now I receive that string over the net, and I need to > figure out what > kind of class is serialized in it. Is there some facility > in Simple > for doing that, or should I prepend some header myself? > > Also, the Simple library is ~180k - is there some stripped > down > version which makes a smaller jar by any chance? > > Thanks for the great tool, > Mark > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support |
|
From: Mark W. <ma...@gm...> - 2008-06-06 11:12:14
|
Hi all,
I've been looking for a fast lightweight java xml serializer for a few
days, just came across Simple, it looks great. I especially like the
compact xml it can produce, since I'm going to be using it for string
message passing across a network.
I'm wondering if there's a quick way to query the class type
serialized in a String, for example, I serialized a class called
Person:
<person a="Bob" b="55">
now I receive that string over the net, and I need to figure out what
kind of class is serialized in it. Is there some facility in Simple
for doing that, or should I prepend some header myself?
Also, the Simple library is ~180k - is there some stripped down
version which makes a smaller jar by any chance?
Thanks for the great tool,
Mark
|
|
From: Niall G. <gal...@ya...> - 2008-06-03 18:59:16
|
Hi, So are you writing multiple separate objects to the file or are you writing one large object. The ids should not repeat as each write and read operation gets a new session created, so although the ids may be the same you will be able to deserialize them separately without any issues using the Persister. However if your document is for external consumption by DOM or SAX or something similar then overriding the getKey() object seems like a reasonable solution. Niall --- Ben Wolfe <si...@be...> wrote: > > Timo > > Yes, I was able to get this effect by writing to the > same stream > multiple times. However, when I did that the > internal ids that > simpleframework puts into the xml document got > repeated. This caused > errors when reading the same stream back in with > simpleframework. > > I fixed this by changing the "key" value that > WriteGraph.getKey() > returns to be done off of an incrementing static > variable instead of the > size of the current graph. > > Niall, is there a better way to do that? > > Ben > > Niall Gallagher wrote: > > Hi, > > > > For some reason I did not get the original message > or > > the follow up to this. It must have gone in to my > spam > > folder. > > > > In answer to your question yes, you can stream > many > > objects to one file. Also, simple should be much > more > > memory efficient than XStream at just about > > everything. > > > > Niall > > > > --- Timo Rumland <cr...@ol...> wrote: > > > >> Hello Alan, > >> > >>> It's not jumping out at me. Is there an > interface > >> where you can > >>> write multiple objects to one file? XStream has > >> object streams for > >>> this purpose... > >> the only way I know is to have a class that wraps > >> references to the > >> objects you would like to serialize. > >> > >> Say we have ObjectA, ObjectB and ObjectC. Just > >> create a class that has > >> references to each of that instances and > serialize > >> that class. > >> > >> I'm not really an expert on SimpleXML, but this > is > >> the only "solution" > >> I know. > >> > >> > >> Regards, > >> Timo > >> > >> > >> > >> > > > ------------------------------------------------------------------------- > >> This SF.net email is sponsored by: Microsoft > >> Defy all challenges. Microsoft(R) Visual Studio > >> 2008. > >> > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > >> _______________________________________________ > >> Simple-support mailing list > >> Sim...@li... > >> > > > https://lists.sourceforge.net/lists/listinfo/simple-support > > > > > > > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio > 2008. > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > Simple-support mailing list > > Sim...@li... > > > https://lists.sourceforge.net/lists/listinfo/simple-support > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio > 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > |
|
From: Ben W. <si...@be...> - 2008-06-03 11:50:08
|
Timo Yes, I was able to get this effect by writing to the same stream multiple times. However, when I did that the internal ids that simpleframework puts into the xml document got repeated. This caused errors when reading the same stream back in with simpleframework. I fixed this by changing the "key" value that WriteGraph.getKey() returns to be done off of an incrementing static variable instead of the size of the current graph. Niall, is there a better way to do that? Ben Niall Gallagher wrote: > Hi, > > For some reason I did not get the original message or > the follow up to this. It must have gone in to my spam > folder. > > In answer to your question yes, you can stream many > objects to one file. Also, simple should be much more > memory efficient than XStream at just about > everything. > > Niall > > --- Timo Rumland <cr...@ol...> wrote: > >> Hello Alan, >> >>> It's not jumping out at me. Is there an interface >> where you can >>> write multiple objects to one file? XStream has >> object streams for >>> this purpose... >> the only way I know is to have a class that wraps >> references to the >> objects you would like to serialize. >> >> Say we have ObjectA, ObjectB and ObjectC. Just >> create a class that has >> references to each of that instances and serialize >> that class. >> >> I'm not really an expert on SimpleXML, but this is >> the only "solution" >> I know. >> >> >> Regards, >> Timo >> >> >> >> > ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio >> 2008. >> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Simple-support mailing list >> Sim...@li... >> > https://lists.sourceforge.net/lists/listinfo/simple-support > > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support |
|
From: Niall G. <gal...@ya...> - 2008-06-03 08:46:54
|
Hi, For some reason I did not get the original message or the follow up to this. It must have gone in to my spam folder. In answer to your question yes, you can stream many objects to one file. Also, simple should be much more memory efficient than XStream at just about everything. Niall --- Timo Rumland <cr...@ol...> wrote: > Hello Alan, > > > It's not jumping out at me. Is there an interface > where you can > > write multiple objects to one file? XStream has > object streams for > > this purpose... > > the only way I know is to have a class that wraps > references to the > objects you would like to serialize. > > Say we have ObjectA, ObjectB and ObjectC. Just > create a class that has > references to each of that instances and serialize > that class. > > I'm not really an expert on SimpleXML, but this is > the only "solution" > I know. > > > Regards, > Timo > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio > 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > |
|
From: Alan G. <al...@bl...> - 2008-06-03 03:39:59
|
On Jun 1, 2008, at 3:46 PM, Timo Rumland wrote: > Hello Alan, > >> It's not jumping out at me. Is there an interface where you can >> write multiple objects to one file? XStream has object streams for >> this purpose... > > the only way I know is to have a class that wraps references to the > objects you would like to serialize. > > Say we have ObjectA, ObjectB and ObjectC. Just create a class that has > references to each of that instances and serialize that class. > > I'm not really an expert on SimpleXML, but this is the only "solution" > I know. I'm sorry if this is a duplicate. I thought I'd sent a response already, but I don't see it in the archives. I'd like to use Simple XML to backup an object database. Ultimately, the number of objects would be too great for a solution that would require them all to be in memory. I'd like to see support for an solution that would allow this sort of streaming implementation. Maybe there is a way to get the same effect by writing to the same file repeatedly? Alan -- Alan Gutierrez | al...@bl... | http://blogometer.com/ | 504 717 1428 Think New Orleans | http://thinknola.com/ |
|
From: Timo R. <cr...@ol...> - 2008-06-01 20:46:37
|
Hello Alan, > It's not jumping out at me. Is there an interface where you can > write multiple objects to one file? XStream has object streams for > this purpose... the only way I know is to have a class that wraps references to the objects you would like to serialize. Say we have ObjectA, ObjectB and ObjectC. Just create a class that has references to each of that instances and serialize that class. I'm not really an expert on SimpleXML, but this is the only "solution" I know. Regards, Timo |