simple-support Mailing List for Simple (Page 77)
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: Stanislaw O. <sta...@ca...> - 2008-02-11 20:52:53
|
Hi once more,
Does the framework currently support serializing/ deserializing maps with
null values (see code below)? The serializer seems to output an empty node
for such entries (with no key), which causes the deserializer to fail.
Obviously, I can hack this around quite easily, but I was wondering if this
is the intended behaviour?
@Root
public class SimpleTest
{
@ElementMap
private Map<String, String> test = new HashMap<String, String>();
public static void main(String [] args) throws Exception
{
SimpleTest test = new SimpleTest();
test.test.put("test", null);
Persister persister = new Persister();
persister.write(test, System.out);
}
}
Cheers,
Staszek
|
|
From: Stanislaw O. <sta...@ca...> - 2008-02-11 19:27:57
|
Hi again, One more question: is there any simple way of having CycleStrategy append id attributes/ resolve references only for objects of certain (known at compilation time) type(s)? The general motivation is that the produced XML is intended to be read/ modified by humans, so I'd like to avoid polluting it with id attributes for object that do not need reference resolution. Cheers, Staszek |
|
From: Stanislaw O. <sta...@ca...> - 2008-02-11 19:21:11
|
Hi Niall,
The best solution, is probably to add the following
> callback method also.
>
> @Persist
> private void persist() {
> for(int i = 0; i < test.size(); i++) {
> Object val = test.get(i);
> String text = String.valueOf(val);
>
> test.set(i, text);
> }
> }
This approach will do the trick for me, thanks!
Cheers,
Staszek
|
|
From: Niall G. <gal...@ya...> - 2008-02-11 18:36:15
|
Hi,
What you have suggested is static, by this I mean that
it is a static value on an annotation. So why not use
getter and setter methods to serialize your values.
For example instead of annotating the field why not
annotate a method.
public class Class1{
@Element
private Class3 class3;
@Attribute
private long id;
}
public class Class2{
@Attribute(name="class1", references=Class1.id)
private Class1 class1;
@Attribute
public long getId() {
return class1.id;
}
@Attribute
public void setId(long id) {
class1 = new Class1();
class1.id = id;
}
}
This will read and write the elements you want from
Class1.
Niall
--- Quirino Zagarese <qu...@la...> wrote:
> Hi and thank you very much for the fast response!
> The @Replace solution works perfectly; anyway I
> wondered if a construct like
> the one I proposed
> could be useful for serialization purpose only.
> I think so cause you don't need any callbacks and
> each class "decides" how
> to be serialized.
> If you think such a functionality to be interesting,
> I'd like to contribute
> it.
> Thank you again
> Regards
>
> 2008/2/8, Niall Gallagher
> <gal...@ya...>:
> >
> > Hi,
> >
> > Yes you can, but not as an attribute of the
> containing
> > class. All you need to do is use the @Replace
> > annotation on a method. For instance if you wish
> to
> > write a single value you should do the following.
> >
> > private Class1 {
> >
> > @Element(required=false)
> > private Blah other;
> >
> > @Attrobite
> > private int id;
> >
> > @Replace
> > private Class1 replace() {
> > if(isSomeCondition()) {
> > Class1 class1 = new Class1();
> > class1.id = id;
> > return class1;
> > }
> > return this;
> > }
> > }
> >
> > public Class2 {
> >
> > @Element
> > private Class1 value;
> > }
> >
> > This will cause a callback to Class1 before its
> > written to XML.
> >
> > Niall
> >
> >
> > --- Quirino Zagarese <qu...@la...>
> wrote:
> >
> > > Hi,
> > > I've been watching the Simple Framework and I
> found
> > > it very useful and
> > > pretty complete.
> > > I looked at tutorials and javadocs and I
> wondered if
> > > it's possible to
> > > serialize only a single field of a complex
> instance
> > > variable. I'll show it
> > > with an example to make it more clear.
> > >
> > > public class Class1{
> > > @Element
> > > private Class3 class3;
> > >
> > > @Attribute
> > > private long id;
> > >
> > > }
> > >
> > >
> > > public class Class2{
> > > //I want to serialize only the id of
> the
> > > class1 variable, not the
> > > whole state
> > > @Attribute(name="class1"
> > > references=Class1.id)
> > > private Class1 class1;
> > >
> > > }
> > >
> > > I'm using Simple to serialize AJAX responses and
> > > this feature could be very
> > > useful when you want to show a list of
> items(i.e.
> > > products in e-commerce
> > > apps), but you don't want to load all related
> data.
> > > Sorry for my English.
> > > Regards
> > >
> > >
> > >
> > > --
> > > Quirino Zagarese
> > >
> > > LaszloItalia Founder (www.laszloitalia.org)
> > > Software Development Manager - Galilaeus s.r.l.
> > > (www.galilaeus.net)
> > > >
> >
>
-------------------------------------------------------------------------
> > > 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
> > >
> >
> >
> >
> >
> >
>
____________________________________________________________________________________
> > Looking for last minute shopping deals?
> > Find them fast with Yahoo! Search.
> >
>
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> >
>
>
>
> --
> Quirino Zagarese
>
> LaszloItalia Founder (www.laszloitalia.org)
> Software Development Manager - Galilaeus s.r.l.
> (www.galilaeus.net)
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|
|
From: Niall G. <gal...@ya...> - 2008-02-10 19:58:36
|
Hi,
Yes you can use different types, however with regard
to primitives you can not type it as "Object". Object
is a special case in that it has no information
regarding the object. Primitives like strings and
integers undergo a different process of serialization,
so if the serializer sees "Object" it thinks the list
contains annotated types, so it attempts to serialize
them as such.
However, in your case because there is no type
information. You can do this.
@Root
public class SimpleTest
{
@ElementList(type=String.class)
private List<Object> test = new
ArrayList<Object>();
public static void main(String [] args) throws
Exception
{
SimpleTest test = new SimpleTest();
test.test.add(10);
test.test.add(0.5);
test.test.add("string");
Persister persister = new Persister();
persister.write(test, System.out);
}
}
which will prodice this following (however you will
have problems deserializing)
<simpleTest>
<test class="java.util.ArrayList">
<string class="java.lang.Integer">10</string>
<string class="java.lang.Double">0.5</string>
<string>string</string>
</test>
</simpleTest>
The best solution, is probably to add the following
callback method also.
@Persist
private void persist() {
for(int i = 0; i < test.size(); i++) {
Object val = test.get(i);
String text = String.valueOf(val);
test.set(i, text);
}
}
This method is called just before serialization. You
can then convert all values to strings, which will
enable deserializaion also, as it produces.
<simpleTest>
<test class="java.util.ArrayList">
<string>10</string>
<string>0.5</string>
<string>string</string>
</test>
</simpleTest>
Niall
--- Stanislaw Osinski <sta...@ca...>
wrote:
> Hello,
>
> First of all, thanks for the great piece of
> software, it simplifies things a
> lot!
>
> I'm not yet an advanced user of Simple XML, hence a
> possibly silly question.
> The following code:
>
> @Root
> public class SimpleTest
> {
> @ElementList
> private List<Object> test = new
> ArrayList<Object>();
>
> public static void main(String [] args) throws
> Exception
> {
> SimpleTest test = new SimpleTest();
> test.test.add(10);
> test.test.add(0.5);
> test.test.add("string");
>
> Persister persister = new Persister();
> persister.write(test, System.out);
> }
> }
>
> produces something like this on output:
>
> <simpleTest>
> <test class="java.util.ArrayList">
> <object class="java.lang.Integer"/>
> <object class="java.lang.Double"/>
> <object class="java.lang.String"/>
> </test>
> </simpleTest>
>
>
> Clearly, the information on output is incomplete to
> deserialize the object
> successfully.
>
> Question: can I (how?) serialize/ deserialize Lists
> and Maps containing
> objects of different types as values?
>
> Cheers,
>
> Staszek
> >
-------------------------------------------------------------------------
> 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
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|
|
From: Stanislaw O. <sta...@ca...> - 2008-02-09 16:29:32
|
Hello,
First of all, thanks for the great piece of software, it simplifies things a
lot!
I'm not yet an advanced user of Simple XML, hence a possibly silly question.
The following code:
@Root
public class SimpleTest
{
@ElementList
private List<Object> test = new ArrayList<Object>();
public static void main(String [] args) throws Exception
{
SimpleTest test = new SimpleTest();
test.test.add(10);
test.test.add(0.5);
test.test.add("string");
Persister persister = new Persister();
persister.write(test, System.out);
}
}
produces something like this on output:
<simpleTest>
<test class="java.util.ArrayList">
<object class="java.lang.Integer"/>
<object class="java.lang.Double"/>
<object class="java.lang.String"/>
</test>
</simpleTest>
Clearly, the information on output is incomplete to deserialize the object
successfully.
Question: can I (how?) serialize/ deserialize Lists and Maps containing
objects of different types as values?
Cheers,
Staszek
|
|
From: Niall G. <gal...@ya...> - 2008-02-08 18:47:09
|
Hi,
Yes you can, but not as an attribute of the containing
class. All you need to do is use the @Replace
annotation on a method. For instance if you wish to
write a single value you should do the following.
private Class1 {
@Element(required=false)
private Blah other;
@Attrobite
private int id;
@Replace
private Class1 replace() {
if(isSomeCondition()) {
Class1 class1 = new Class1();
class1.id = id;
return class1;
}
return this;
}
}
public Class2 {
@Element
private Class1 value;
}
This will cause a callback to Class1 before its
written to XML.
Niall
--- Quirino Zagarese <qu...@la...> wrote:
> Hi,
> I've been watching the Simple Framework and I found
> it very useful and
> pretty complete.
> I looked at tutorials and javadocs and I wondered if
> it's possible to
> serialize only a single field of a complex instance
> variable. I'll show it
> with an example to make it more clear.
>
> public class Class1{
> @Element
> private Class3 class3;
>
> @Attribute
> private long id;
>
> }
>
>
> public class Class2{
> //I want to serialize only the id of the
> class1 variable, not the
> whole state
> @Attribute(name="class1"
> references=Class1.id)
> private Class1 class1;
>
> }
>
> I'm using Simple to serialize AJAX responses and
> this feature could be very
> useful when you want to show a list of items(i.e.
> products in e-commerce
> apps), but you don't want to load all related data.
> Sorry for my English.
> Regards
>
>
>
> --
> Quirino Zagarese
>
> LaszloItalia Founder (www.laszloitalia.org)
> Software Development Manager - Galilaeus s.r.l.
> (www.galilaeus.net)
> >
-------------------------------------------------------------------------
> 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
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
|
|
From: Quirino Z. <qu...@la...> - 2008-02-08 12:44:26
|
Hi,
I've been watching the Simple Framework and I found it very useful and
pretty complete.
I looked at tutorials and javadocs and I wondered if it's possible to
serialize only a single field of a complex instance variable. I'll show it
with an example to make it more clear.
public class Class1{
@Element
private Class3 class3;
@Attribute
private long id;
}
public class Class2{
//I want to serialize only the id of the class1 variable, not the
whole state
@Attribute(name="class1" references=Class1.id)
private Class1 class1;
}
I'm using Simple to serialize AJAX responses and this feature could be very
useful when you want to show a list of items(i.e. products in e-commerce
apps), but you don't want to load all related data.
Sorry for my English.
Regards
--
Quirino Zagarese
LaszloItalia Founder (www.laszloitalia.org)
Software Development Manager - Galilaeus s.r.l. (www.galilaeus.net)
|
|
From: Niall G. <gal...@ya...> - 2008-02-07 18:45:53
|
Hi, What problem do you see? Is there a stack trace? These libraries are loaded via the normal class loading process. Niall --- Michael Ebstyne <meb...@ma...> wrote: > I love simple-xml. But, I presently have one issue > with it that I'm > hoping I can get some help with. It relies on the > stax-1.2.0.jar > and the stax-api-1.0.1.jar. Due to some reasons out > of my control > I have to modify the source code in those libraries. > Thus far I > have been unable to locate the source. It would be > really helpful > if someone could get me pointed in the right > direction or give me > a clear explanation as to why this is a lost cause. > > Thanks much, > > Michael > > PS For those curious as to why I'm in this pickle... > I'm using a > scripting > framework that did not do a very good job > implementing it's class > loader. > As a consequence, in the framework, all java > libraries that call the > class > loader via the > Thread.getCurrentThread().getClassLoader() interface > do > not actually get the full class library. Instead > one must invoke the > class > loader via the object.getClass().getClassLoader() > interface. It's > subtle. > But, the effect is night and day for this situation. > And, > unfortunately, > abandoning the scripting framework is not an option. > > ------------------------------------------------------------------------- > 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 > ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ |
|
From: Michael E. <meb...@ma...> - 2008-02-07 11:30:34
|
I love simple-xml. But, I presently have one issue with it that I'm hoping I can get some help with. It relies on the stax-1.2.0.jar and the stax-api-1.0.1.jar. Due to some reasons out of my control I have to modify the source code in those libraries. Thus far I have been unable to locate the source. It would be really helpful if someone could get me pointed in the right direction or give me a clear explanation as to why this is a lost cause. Thanks much, Michael PS For those curious as to why I'm in this pickle... I'm using a scripting framework that did not do a very good job implementing it's class loader. As a consequence, in the framework, all java libraries that call the class loader via the Thread.getCurrentThread().getClassLoader() interface do not actually get the full class library. Instead one must invoke the class loader via the object.getClass().getClassLoader() interface. It's subtle. But, the effect is night and day for this situation. And, unfortunately, abandoning the scripting framework is not an option. |
|
From: Timo R. <cr...@ol...> - 2008-02-04 20:23:07
|
Hello Niall,
> You can do the following do deserialize.
> Object x = new Persister().read(new
> FileInputStream("file.xml"), "UTF-8")
> This will read the file in UTF-8. There should be no issues. I have
> a test case for this also. Let me know if you still see the issue,
> it should work fine.
It works - thanks a lot for your help!
Regards,
Timo
|
|
From: Niall G. <gal...@ya...> - 2008-02-04 19:30:56
|
Hi,
You can do the following do deserialize.
Object x = new Persister().read(new
FileInputStream("file.xml"), "UTF-8")
This will read the file in UTF-8. There should be no
issues. I have a test case for this also.
Let me know if you still see the issue, it should work
fine.
Niall
--- Timo Rumland <cr...@ol...> wrote:
> Hello,
>
> I love to use the Simple XML Framework, it makes
> things so much easier
> for me.
>
> I have a question regarding character encoding. I
> have this XML file:
>
> --------
> <?xml version="1.0" encoding="UTF-8"?>
> <navigationBarModel>
> <node text="sampletext"/>
> </navigationBarModel>
> --------
>
> I can deserialize it without problems. But when the
> text attribute of
> the "node" tag is set to a text with a character
> other than in the
> ASCII set, e.g. "another character: Ä" (Ä is the
> german umlaut for the
> character A), the deserialization of the text
> attibute is not correct.
> The text-string contains something like
>
> "another character: Ã"
>
> How can I use characters from the Unicode encoding
> in my xml
> tags/attributes?
>
>
> Thanks a lot for your help!
>
>
> Regards,
> Timo Rumland
>
>
>
-------------------------------------------------------------------------
> 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
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
|
|
From: Timo R. <cr...@ol...> - 2008-02-04 11:17:15
|
Hello,
I love to use the Simple XML Framework, it makes things so much easier
for me.
I have a question regarding character encoding. I have this XML file:
--------
<?xml version="1.0" encoding="UTF-8"?>
<navigationBarModel>
<node text="sampletext"/>
</navigationBarModel>
--------
I can deserialize it without problems. But when the text attribute of
the "node" tag is set to a text with a character other than in the
ASCII set, e.g. "another character: Ä" (Ä is the german umlaut for the
character A), the deserialization of the text attibute is not correct.
The text-string contains something like
"another character: Ã"
How can I use characters from the Unicode encoding in my xml
tags/attributes?
Thanks a lot for your help!
Regards,
Timo Rumland
|
|
From: Niall G. <gal...@ya...> - 2007-12-31 16:27:38
|
Hi,
I have fixed this issue and I have attached the patch,
which will go in to the next release.
Niall
--- Niall Gallagher <gal...@ya...> wrote:
> Hi Frank,
>
> Well firstly I think there maybe an error in you
> example. As there is no @Enity annotation. However I
> am sure you are using @Element, in which case the
> class="MyValidator" does not contain the package
> name
> of the validator object.
>
> The reason you get a TransformException is because
> it
> thinks you are trying to read an IValidator, which
> does not have any XML annotations. So you need to
> ensure the class="<class name>" is a valid class.
>
> Niall
>
>
> --- Frank Castellucci <fra...@gm...> wrote:
>
> > IValidator.java
> > ===========
> > public interface IValidator
> > {
> >
> > }
> >
> > MyValidator.java
> > ============
> > @Root
> > public class MyValidator implements IValidator,
> > Serializable
> > {
> > @Element(name="model-class",required=true)
> > private String clazzName;
> >
> > @Element(required=false)
> > private String description
> > }
> >
> > Item.java
> > =======
> > @Root(name="item")
> > public class Item
> > {
> > @Entity(name="validate")
> > private IValidator ivalidator;
> > }
> >
> > test.xml
> > ======
> > <item>
> > <validate class="MyValidator">
> > <model-class>xxx.yyy.zzz</model-class>
> > </validate>
> > </item>
> >
> > While I've omitted other attributes and entities,
> > here is the top portion of
> > the exception I get:
> >
> >
>
org.simpleframework.xml.transform.TransformException:
> > Transform of interface
> > org.fvjc.wd.validator.IValidator not supported
> > at
> >
>
org.simpleframework.xml.transform.PackageMatcher.match(
> > PackageMatcher.java:91)
> > at
> >
>
org.simpleframework.xml.transform.DefaultMatcher.matchType(
> > DefaultMatcher.java:111)
> > at
> >
>
org.simpleframework.xml.transform.DefaultMatcher.match(
> > DefaultMatcher.java:90)
> > at
> >
>
org.simpleframework.xml.transform.Transformer.read(Transformer.java
> > :106)
> > at
> >
>
org.simpleframework.xml.load.PrimitiveFactory.getInstance(
> > PrimitiveFactory.java:104)
> > at
> >
>
org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
> > :196)
> > at
> >
>
org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
> > :178)
> > at
> >
>
org.simpleframework.xml.load.Primitive.readElement(Primitive.java
> > :150)
> > at
> >
>
org.simpleframework.xml.load.Primitive.readElement(Primitive.java
> > :133)
> >
> > Any help would be appreciated
> > >
>
-------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio
> > 2005.
> >
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
> _______________________________________________
> > Simple-support mailing list
> > Sim...@li...
> >
>
https://lists.sourceforge.net/lists/listinfo/simple-support
> >
>
>
>
>
>
____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
>
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
>
-------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio
> 2005.
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
>
https://lists.sourceforge.net/lists/listinfo/simple-support
>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
|
|
From: Niall G. <gal...@ya...> - 2007-12-28 16:22:58
|
Hi Frank,
Well firstly I think there maybe an error in you
example. As there is no @Enity annotation. However I
am sure you are using @Element, in which case the
class="MyValidator" does not contain the package name
of the validator object.
The reason you get a TransformException is because it
thinks you are trying to read an IValidator, which
does not have any XML annotations. So you need to
ensure the class="<class name>" is a valid class.
Niall
--- Frank Castellucci <fra...@gm...> wrote:
> IValidator.java
> ===========
> public interface IValidator
> {
>
> }
>
> MyValidator.java
> ============
> @Root
> public class MyValidator implements IValidator,
> Serializable
> {
> @Element(name="model-class",required=true)
> private String clazzName;
>
> @Element(required=false)
> private String description
> }
>
> Item.java
> =======
> @Root(name="item")
> public class Item
> {
> @Entity(name="validate")
> private IValidator ivalidator;
> }
>
> test.xml
> ======
> <item>
> <validate class="MyValidator">
> <model-class>xxx.yyy.zzz</model-class>
> </validate>
> </item>
>
> While I've omitted other attributes and entities,
> here is the top portion of
> the exception I get:
>
>
org.simpleframework.xml.transform.TransformException:
> Transform of interface
> org.fvjc.wd.validator.IValidator not supported
> at
>
org.simpleframework.xml.transform.PackageMatcher.match(
> PackageMatcher.java:91)
> at
>
org.simpleframework.xml.transform.DefaultMatcher.matchType(
> DefaultMatcher.java:111)
> at
>
org.simpleframework.xml.transform.DefaultMatcher.match(
> DefaultMatcher.java:90)
> at
>
org.simpleframework.xml.transform.Transformer.read(Transformer.java
> :106)
> at
>
org.simpleframework.xml.load.PrimitiveFactory.getInstance(
> PrimitiveFactory.java:104)
> at
>
org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
> :196)
> at
>
org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
> :178)
> at
>
org.simpleframework.xml.load.Primitive.readElement(Primitive.java
> :150)
> at
>
org.simpleframework.xml.load.Primitive.readElement(Primitive.java
> :133)
>
> Any help would be appreciated
> >
-------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio
> 2005.
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
_______________________________________________
> Simple-support mailing list
> Sim...@li...
>
https://lists.sourceforge.net/lists/listinfo/simple-support
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
|
|
From: Frank C. <fra...@gm...> - 2007-12-22 12:31:50
|
IValidator.java
===========
public interface IValidator
{
}
MyValidator.java
============
@Root
public class MyValidator implements IValidator, Serializable
{
@Element(name="model-class",required=true)
private String clazzName;
@Element(required=false)
private String description
}
Item.java
=======
@Root(name="item")
public class Item
{
@Entity(name="validate")
private IValidator ivalidator;
}
test.xml
======
<item>
<validate class="MyValidator">
<model-class>xxx.yyy.zzz</model-class>
</validate>
</item>
While I've omitted other attributes and entities, here is the top portion of
the exception I get:
org.simpleframework.xml.transform.TransformException: Transform of interface
org.fvjc.wd.validator.IValidator not supported
at org.simpleframework.xml.transform.PackageMatcher.match(
PackageMatcher.java:91)
at org.simpleframework.xml.transform.DefaultMatcher.matchType(
DefaultMatcher.java:111)
at org.simpleframework.xml.transform.DefaultMatcher.match(
DefaultMatcher.java:90)
at org.simpleframework.xml.transform.Transformer.read(Transformer.java
:106)
at org.simpleframework.xml.load.PrimitiveFactory.getInstance(
PrimitiveFactory.java:104)
at org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
:196)
at org.simpleframework.xml.load.Primitive.readTemplate(Primitive.java
:178)
at org.simpleframework.xml.load.Primitive.readElement(Primitive.java
:150)
at org.simpleframework.xml.load.Primitive.readElement(Primitive.java
:133)
Any help would be appreciated
|
|
From: Niall G. <gal...@ya...> - 2007-12-17 20:50:20
|
Hi
The only suggestion I have for this is to not use the
same types, and have the short form resolve as the
long form. Also the long form would have to be
replaced by the short form like so:
@Root
public abstract class Form {
@Attribute
protected String name;
@Attribute
protected int version;
public Form(String name, int version) {
this.name = name;
this.version = version;
}
}
@Root
public class ShortForm extends Form {
public ShortForm(String name, int version) {
super(name, int version);
}
@Resolve
public Form getResolve() {
return new LongForm(name, version);
}
}
@Root
public class LongForm extends ShortForm {
@Text
private String text;
public LongForm(String name, int version) {
super(name, version);
}
@Replace
public Form getReplace() {
String name = LongForm.class.getName();
if(!isShortForm(map)) {
return this;
}
return new ShortForm(name, version);
}
@Resolve
public Form getResolve(Map map) {
return this;
}
}
public class ShortDecorator implements Strategy {
private Strategy strategy;
public ShortDecorator(Strategy strategy) {
this.strategy = strategy;
}
public Type getElement(Class field, NodeMap node,
Map map) {
// Perform attribute modification on class=
return strategy.getElement(field, node, map);
}
public boolean setElement(Class field, Object
value, NodeMap node, Map map) {
// Perform attribute modification
return strategy.setElement(field, value, node,
map);
}
// Etc..
}
--- Ben Wolfe <si...@be...> wrote:
>
> This is a reasonable enough hack, so I think I'll
> run with it. Thanks!
>
> The only concern I have is the object value
> validation. I'd rather not
> have to mark all of my elements as "required=false"
> just to be able to
> shorten objects down to primary keys. Is there a
> way to turn off the
> "required" checking if the @Replace method is
> invoked? Perhaps a call
> from the converter to the strategy to confirm
> whether something needs
> validation or not.
>
> This would all me to use my "Short" serializer for
> both serializing and
> deserializing on objects that have the primary keys
> only filled in but
> also have some elements marked as "required=true".
> If the user chooses
> to deserialize or serialize with the normal
> serializer, those elements
> are validated and errors are thrown if they do not
> have values.
>
> Ben
>
> Niall Gallagher wrote:
> > Hi,
> >
> > Currently the only ways to use the session Map are
> the
> > following:
> >
> > Strategy.setRoot // last parameter is the session
> > Strategy.setElement // last parameter is the
> session
> > Strategy.getRoot // last parameter is the session
> > Strategy.getElement // last parameter is the
> session
> >
> > @Replace
> > @Resolve
> > @Persist
> > @Complete
> > @Validate
> > @Commit
> >
> > All methods for the above annotations will accept
> the
> > session map. I guess the best way to deal with
> this is
> > to use the Strategy.setRoot as its called once for
> the
> > very first element before anything is persisted.
> >
> > Niall
> >
> > --- Ben Wolfe <si...@be...> wrote:
> >
> >> Using @Persist and @Complete won't work for a few
> >> reasons. We're using
> >> a hibernate backend. Modifications to the object
> >> will make it into the
> >> database. Adding calls to our 20+ pojos to clear
> >> out and refill the
> >> object just isn't plausible.
> >>
> >> The @Replace/@Resolve seems to be the best bet.
> It
> >> doesn't effect the
> >> root class -- which is what we want. The only
> need
> >> would be to have it
> >> act conditionally. It looks like the @Replace
> >> method will take in a
> >> "Map sessionData" object. Is there a way I can
> add
> >> things to that map
> >> when I create the Persister? Or is the only way
> to
> >> modify that map by
> >> doing so in the
> @Persist/@Complete/@Replace/@Resolve
> >> methods?
> >>
> >> Thanks,
> >> Ben
> >>
> >> Niall Gallagher wrote:
> >>> Hi,
> >>>
> >>> Take a look at the following unit test.
> >>>
> >>>
> >
>
http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/SubstituteTest.java
> >>> This shows the @Replace and @Resolve methods
> >> working.
> >>> The reason you could not get your test to run is
> >>> because the very root Class within the schema
> >> cannot
> >>> be replaced, only fields of a composite class.
> For
> >>> instance if the class schema you defined was a
> >> field
> >>> of some other class then it would replace fine.
> >>>
> >>> With respect to you global property suggestion,
> >> why
> >>> not just use the session map to pass information
> >>> about, it will be passed to the @Persist and
> >> @Complete
> >>> annotated methods. For example:
> >>>
> >>> @Persist
> >>> private void persistMe(Map session) {
> >>> // use session here before serialization...
> >>> }
> >>>
> >>> @Complete
> >>> private void completeMe(Map session) {
> >>> // use the session here after
> serialization...
> >>> }
> >>>
> >>> This is just one way, there are tonnes of other
> >> ways
> >>> this can be done.
> >>>
> >>> Niall
> >>>
> >>> --- Ben Wolfe <si...@be...> wrote:
> >>>
> >>>> I can't seem to get the Replace method to work.
>
> >>>> I've attached a test
> >>>> method to demonstrate. Perhaps you can show me
> >> what
> >>>> I'm doing wrong. :-/
> >>>>
> >>>> The @Replace/@Resolve methods have promise, but
> I
> >>>> still don't see a way
> >>>> for the person serializing to trigger it. The
> >>>> closest solution would be
> >>>> if "someProperty" in your example below were
> >>>> actually a global property
> >>>> set/retrieved via a call to a util class.
> >> However,
> >>>> our code is running
> >>>> on a server, and it is quite possible that
> >> multiple
> >>>> serializations will
> >>>> be happening at the same time -- some "primary
> >> key
> >>>> only" and some full.
> >>>>
> >>>> >public Object myResolveMethod() {
> >>>> > if(someProperty) {
> >>>> > return new SomeOtherObject(myProperty1,
> >>>> myProperty2);
> >>>> > }
> >>>> > return this; // Here I am saying don't
> read
> >>>> resolve
> >>>> >}
> >>>>
> >>>> I have coded up the tags possibility. I can
> >> submit
> >>>> a patch if you're
> >>>> interested. :-)
> >>>>
> >>>> Ben
> >>>>
> >>>> Niall Gallagher wrote:
> >>>>> Hi,
> >>>>>
> >>>>> Forgot to explain the following code snippit.
> >> This
> >>>>> demonstrates how an @Replace method could be
> >> used
> >>>>> instead of a @Resolve. The @Replace is used in
> >>>>> writing, it is similar to Java object
> >>>> serialization
> >>>>> writeReplace.
> >>>>>
> >>>>> @Root
> >>>>> public class SomeObject {
> >>>>>
> >>>>> @Element(required=false)
> >>>>> private String text;
> >>>>>
> >>>>> @Attribute(required=false)
> >>>>> private int version;
> >>>>>
> >>>>> @Attribute
> >>>>> private String key;
> >>>>>
>
=== message truncated ===
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|
|
From: Ben W. <si...@be...> - 2007-12-17 19:52:07
|
This is a reasonable enough hack, so I think I'll run with it. Thanks! The only concern I have is the object value validation. I'd rather not have to mark all of my elements as "required=false" just to be able to shorten objects down to primary keys. Is there a way to turn off the "required" checking if the @Replace method is invoked? Perhaps a call from the converter to the strategy to confirm whether something needs validation or not. This would all me to use my "Short" serializer for both serializing and deserializing on objects that have the primary keys only filled in but also have some elements marked as "required=true". If the user chooses to deserialize or serialize with the normal serializer, those elements are validated and errors are thrown if they do not have values. Ben Niall Gallagher wrote: > Hi, > > Currently the only ways to use the session Map are the > following: > > Strategy.setRoot // last parameter is the session > Strategy.setElement // last parameter is the session > Strategy.getRoot // last parameter is the session > Strategy.getElement // last parameter is the session > > @Replace > @Resolve > @Persist > @Complete > @Validate > @Commit > > All methods for the above annotations will accept the > session map. I guess the best way to deal with this is > to use the Strategy.setRoot as its called once for the > very first element before anything is persisted. > > Niall > > --- Ben Wolfe <si...@be...> wrote: > >> Using @Persist and @Complete won't work for a few >> reasons. We're using >> a hibernate backend. Modifications to the object >> will make it into the >> database. Adding calls to our 20+ pojos to clear >> out and refill the >> object just isn't plausible. >> >> The @Replace/@Resolve seems to be the best bet. It >> doesn't effect the >> root class -- which is what we want. The only need >> would be to have it >> act conditionally. It looks like the @Replace >> method will take in a >> "Map sessionData" object. Is there a way I can add >> things to that map >> when I create the Persister? Or is the only way to >> modify that map by >> doing so in the @Persist/@Complete/@Replace/@Resolve >> methods? >> >> Thanks, >> Ben >> >> Niall Gallagher wrote: >>> Hi, >>> >>> Take a look at the following unit test. >>> >>> > http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/SubstituteTest.java >>> This shows the @Replace and @Resolve methods >> working. >>> The reason you could not get your test to run is >>> because the very root Class within the schema >> cannot >>> be replaced, only fields of a composite class. For >>> instance if the class schema you defined was a >> field >>> of some other class then it would replace fine. >>> >>> With respect to you global property suggestion, >> why >>> not just use the session map to pass information >>> about, it will be passed to the @Persist and >> @Complete >>> annotated methods. For example: >>> >>> @Persist >>> private void persistMe(Map session) { >>> // use session here before serialization... >>> } >>> >>> @Complete >>> private void completeMe(Map session) { >>> // use the session here after serialization... >>> } >>> >>> This is just one way, there are tonnes of other >> ways >>> this can be done. >>> >>> Niall >>> >>> --- Ben Wolfe <si...@be...> wrote: >>> >>>> I can't seem to get the Replace method to work. >>>> I've attached a test >>>> method to demonstrate. Perhaps you can show me >> what >>>> I'm doing wrong. :-/ >>>> >>>> The @Replace/@Resolve methods have promise, but I >>>> still don't see a way >>>> for the person serializing to trigger it. The >>>> closest solution would be >>>> if "someProperty" in your example below were >>>> actually a global property >>>> set/retrieved via a call to a util class. >> However, >>>> our code is running >>>> on a server, and it is quite possible that >> multiple >>>> serializations will >>>> be happening at the same time -- some "primary >> key >>>> only" and some full. >>>> >>>> >public Object myResolveMethod() { >>>> > if(someProperty) { >>>> > return new SomeOtherObject(myProperty1, >>>> myProperty2); >>>> > } >>>> > return this; // Here I am saying don't read >>>> resolve >>>> >} >>>> >>>> I have coded up the tags possibility. I can >> submit >>>> a patch if you're >>>> interested. :-) >>>> >>>> Ben >>>> >>>> Niall Gallagher wrote: >>>>> Hi, >>>>> >>>>> Forgot to explain the following code snippit. >> This >>>>> demonstrates how an @Replace method could be >> used >>>>> instead of a @Resolve. The @Replace is used in >>>>> writing, it is similar to Java object >>>> serialization >>>>> writeReplace. >>>>> >>>>> @Root >>>>> public class SomeObject { >>>>> >>>>> @Element(required=false) >>>>> private String text; >>>>> >>>>> @Attribute(required=false) >>>>> private int version; >>>>> >>>>> @Attribute >>>>> private String key; >>>>> >>>>> public SomeObject() { >>>>> super(); >>>>> } >>>>> >>>>> public SomeObject(String key) { >>>>> this.key = key; >>>>> } >>>>> >>>>> @Validate >>>>> public void validate() { >>>>> // do some validation here... >>>>> } >>>>> >>>>> @Replace >>>>> private Object writeReplace() { >>>>> return new SomeObject(key); // Here I >>>> provide >>>>> the same type with a subset of the properties >>>>> } >>>>> } >>>>> >>>>> You could also use the @Persist and @Complete, >> the >>>>> method annotated with @Persist is called just >>>> before >>>>> serialization of the object, and @Complete is >>>> called >>>>> directly after. So you can modify the contents >> of >>>> the >>>>> object before it is serialized and bring the >>>> object >>>>> back to a known state when you have finished >>>>> serializing it. So you get a chance to modify >> the >>>>> object for serialization, there is an example in >>>> the >>>>> tutorial. >>>>> >>>>> Niall >>>>> >>>>> --- Niall Gallagher <gal...@ya...> >>>> wrote: >>>>>> Hi, >>>>>> >>>>>> This will give you both worlds. Why not do the >>>>>> following: >>>>>> >>>>>> public Object myResolveMethod() { >>>>>> if(someProperty) { >>>>>> return new SomeOtherObject(myProperty1, >>>>>> myProperty2); >>>>>> } >>>>>> return this; // Here I am saying don't read >>>>>> resolve >>>>>> } >>>>>> >>>>>> When you return "this" from the method >> annotated >>>>>> with >>>>>> @Resolve annotation you are saying not to >> resolve >>>> to >>>>>> something different. Also, you don't need to >>>> return >>>>>> a >>>>>> different type. >>>>>> >>>>>> >>>>>> @Root >>>>>> public class SomeObject { > === message truncated === > > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping |
|
From: Niall G. <gal...@ya...> - 2007-12-14 19:36:14
|
Hi, Currently the only ways to use the session Map are the following: Strategy.setRoot // last parameter is the session Strategy.setElement // last parameter is the session Strategy.getRoot // last parameter is the session Strategy.getElement // last parameter is the session @Replace @Resolve @Persist @Complete @Validate @Commit All methods for the above annotations will accept the session map. I guess the best way to deal with this is to use the Strategy.setRoot as its called once for the very first element before anything is persisted. Niall --- Ben Wolfe <si...@be...> wrote: > > Using @Persist and @Complete won't work for a few > reasons. We're using > a hibernate backend. Modifications to the object > will make it into the > database. Adding calls to our 20+ pojos to clear > out and refill the > object just isn't plausible. > > The @Replace/@Resolve seems to be the best bet. It > doesn't effect the > root class -- which is what we want. The only need > would be to have it > act conditionally. It looks like the @Replace > method will take in a > "Map sessionData" object. Is there a way I can add > things to that map > when I create the Persister? Or is the only way to > modify that map by > doing so in the @Persist/@Complete/@Replace/@Resolve > methods? > > Thanks, > Ben > > Niall Gallagher wrote: > > Hi, > > > > Take a look at the following unit test. > > > > > http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/SubstituteTest.java > > > > This shows the @Replace and @Resolve methods > working. > > The reason you could not get your test to run is > > because the very root Class within the schema > cannot > > be replaced, only fields of a composite class. For > > instance if the class schema you defined was a > field > > of some other class then it would replace fine. > > > > With respect to you global property suggestion, > why > > not just use the session map to pass information > > about, it will be passed to the @Persist and > @Complete > > annotated methods. For example: > > > > @Persist > > private void persistMe(Map session) { > > // use session here before serialization... > > } > > > > @Complete > > private void completeMe(Map session) { > > // use the session here after serialization... > > } > > > > This is just one way, there are tonnes of other > ways > > this can be done. > > > > Niall > > > > --- Ben Wolfe <si...@be...> wrote: > > > >> I can't seem to get the Replace method to work. > >> I've attached a test > >> method to demonstrate. Perhaps you can show me > what > >> I'm doing wrong. :-/ > >> > >> The @Replace/@Resolve methods have promise, but I > >> still don't see a way > >> for the person serializing to trigger it. The > >> closest solution would be > >> if "someProperty" in your example below were > >> actually a global property > >> set/retrieved via a call to a util class. > However, > >> our code is running > >> on a server, and it is quite possible that > multiple > >> serializations will > >> be happening at the same time -- some "primary > key > >> only" and some full. > >> > >> >public Object myResolveMethod() { > >> > if(someProperty) { > >> > return new SomeOtherObject(myProperty1, > >> myProperty2); > >> > } > >> > return this; // Here I am saying don't read > >> resolve > >> >} > >> > >> I have coded up the tags possibility. I can > submit > >> a patch if you're > >> interested. :-) > >> > >> Ben > >> > >> Niall Gallagher wrote: > >>> Hi, > >>> > >>> Forgot to explain the following code snippit. > This > >>> demonstrates how an @Replace method could be > used > >>> instead of a @Resolve. The @Replace is used in > >>> writing, it is similar to Java object > >> serialization > >>> writeReplace. > >>> > >>> @Root > >>> public class SomeObject { > >>> > >>> @Element(required=false) > >>> private String text; > >>> > >>> @Attribute(required=false) > >>> private int version; > >>> > >>> @Attribute > >>> private String key; > >>> > >>> public SomeObject() { > >>> super(); > >>> } > >>> > >>> public SomeObject(String key) { > >>> this.key = key; > >>> } > >>> > >>> @Validate > >>> public void validate() { > >>> // do some validation here... > >>> } > >>> > >>> @Replace > >>> private Object writeReplace() { > >>> return new SomeObject(key); // Here I > >> provide > >>> the same type with a subset of the properties > >>> } > >>> } > >>> > >>> You could also use the @Persist and @Complete, > the > >>> method annotated with @Persist is called just > >> before > >>> serialization of the object, and @Complete is > >> called > >>> directly after. So you can modify the contents > of > >> the > >>> object before it is serialized and bring the > >> object > >>> back to a known state when you have finished > >>> serializing it. So you get a chance to modify > the > >>> object for serialization, there is an example in > >> the > >>> tutorial. > >>> > >>> Niall > >>> > >>> --- Niall Gallagher <gal...@ya...> > >> wrote: > >>>> Hi, > >>>> > >>>> This will give you both worlds. Why not do the > >>>> following: > >>>> > >>>> public Object myResolveMethod() { > >>>> if(someProperty) { > >>>> return new SomeOtherObject(myProperty1, > >>>> myProperty2); > >>>> } > >>>> return this; // Here I am saying don't read > >>>> resolve > >>>> } > >>>> > >>>> When you return "this" from the method > annotated > >>>> with > >>>> @Resolve annotation you are saying not to > resolve > >> to > >>>> something different. Also, you don't need to > >> return > >>>> a > >>>> different type. > >>>> > >>>> > >>>> @Root > >>>> public class SomeObject { > === message truncated === ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping |
|
From: Niall G. <gal...@ya...> - 2007-12-14 19:31:17
|
Hi, Currently the only ways to use the session Map ar --- Ben Wolfe <si...@be...> wrote: > > Using @Persist and @Complete won't work for a few > reasons. We're using > a hibernate backend. Modifications to the object > will make it into the > database. Adding calls to our 20+ pojos to clear > out and refill the > object just isn't plausible. > > The @Replace/@Resolve seems to be the best bet. It > doesn't effect the > root class -- which is what we want. The only need > would be to have it > act conditionally. It looks like the @Replace > method will take in a > "Map sessionData" object. Is there a way I can add > things to that map > when I create the Persister? Or is the only way to > modify that map by > doing so in the @Persist/@Complete/@Replace/@Resolve > methods? > > Thanks, > Ben > > Niall Gallagher wrote: > > Hi, > > > > Take a look at the following unit test. > > > > > http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/SubstituteTest.java > > > > This shows the @Replace and @Resolve methods > working. > > The reason you could not get your test to run is > > because the very root Class within the schema > cannot > > be replaced, only fields of a composite class. For > > instance if the class schema you defined was a > field > > of some other class then it would replace fine. > > > > With respect to you global property suggestion, > why > > not just use the session map to pass information > > about, it will be passed to the @Persist and > @Complete > > annotated methods. For example: > > > > @Persist > > private void persistMe(Map session) { > > // use session here before serialization... > > } > > > > @Complete > > private void completeMe(Map session) { > > // use the session here after serialization... > > } > > > > This is just one way, there are tonnes of other > ways > > this can be done. > > > > Niall > > > > --- Ben Wolfe <si...@be...> wrote: > > > >> I can't seem to get the Replace method to work. > >> I've attached a test > >> method to demonstrate. Perhaps you can show me > what > >> I'm doing wrong. :-/ > >> > >> The @Replace/@Resolve methods have promise, but I > >> still don't see a way > >> for the person serializing to trigger it. The > >> closest solution would be > >> if "someProperty" in your example below were > >> actually a global property > >> set/retrieved via a call to a util class. > However, > >> our code is running > >> on a server, and it is quite possible that > multiple > >> serializations will > >> be happening at the same time -- some "primary > key > >> only" and some full. > >> > >> >public Object myResolveMethod() { > >> > if(someProperty) { > >> > return new SomeOtherObject(myProperty1, > >> myProperty2); > >> > } > >> > return this; // Here I am saying don't read > >> resolve > >> >} > >> > >> I have coded up the tags possibility. I can > submit > >> a patch if you're > >> interested. :-) > >> > >> Ben > >> > >> Niall Gallagher wrote: > >>> Hi, > >>> > >>> Forgot to explain the following code snippit. > This > >>> demonstrates how an @Replace method could be > used > >>> instead of a @Resolve. The @Replace is used in > >>> writing, it is similar to Java object > >> serialization > >>> writeReplace. > >>> > >>> @Root > >>> public class SomeObject { > >>> > >>> @Element(required=false) > >>> private String text; > >>> > >>> @Attribute(required=false) > >>> private int version; > >>> > >>> @Attribute > >>> private String key; > >>> > >>> public SomeObject() { > >>> super(); > >>> } > >>> > >>> public SomeObject(String key) { > >>> this.key = key; > >>> } > >>> > >>> @Validate > >>> public void validate() { > >>> // do some validation here... > >>> } > >>> > >>> @Replace > >>> private Object writeReplace() { > >>> return new SomeObject(key); // Here I > >> provide > >>> the same type with a subset of the properties > >>> } > >>> } > >>> > >>> You could also use the @Persist and @Complete, > the > >>> method annotated with @Persist is called just > >> before > >>> serialization of the object, and @Complete is > >> called > >>> directly after. So you can modify the contents > of > >> the > >>> object before it is serialized and bring the > >> object > >>> back to a known state when you have finished > >>> serializing it. So you get a chance to modify > the > >>> object for serialization, there is an example in > >> the > >>> tutorial. > >>> > >>> Niall > >>> > >>> --- Niall Gallagher <gal...@ya...> > >> wrote: > >>>> Hi, > >>>> > >>>> This will give you both worlds. Why not do the > >>>> following: > >>>> > >>>> public Object myResolveMethod() { > >>>> if(someProperty) { > >>>> return new SomeOtherObject(myProperty1, > >>>> myProperty2); > >>>> } > >>>> return this; // Here I am saying don't read > >>>> resolve > >>>> } > >>>> > >>>> When you return "this" from the method > annotated > >>>> with > >>>> @Resolve annotation you are saying not to > resolve > >> to > >>>> something different. Also, you don't need to > >> return > >>>> a > >>>> different type. > >>>> > >>>> > >>>> @Root > >>>> public class SomeObject { > === message truncated === ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs |
|
From: Ben W. <si...@be...> - 2007-12-14 15:13:43
|
Using @Persist and @Complete won't work for a few reasons. We're using a hibernate backend. Modifications to the object will make it into the database. Adding calls to our 20+ pojos to clear out and refill the object just isn't plausible. The @Replace/@Resolve seems to be the best bet. It doesn't effect the root class -- which is what we want. The only need would be to have it act conditionally. It looks like the @Replace method will take in a "Map sessionData" object. Is there a way I can add things to that map when I create the Persister? Or is the only way to modify that map by doing so in the @Persist/@Complete/@Replace/@Resolve methods? Thanks, Ben Niall Gallagher wrote: > Hi, > > Take a look at the following unit test. > > http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/SubstituteTest.java > > This shows the @Replace and @Resolve methods working. > The reason you could not get your test to run is > because the very root Class within the schema cannot > be replaced, only fields of a composite class. For > instance if the class schema you defined was a field > of some other class then it would replace fine. > > With respect to you global property suggestion, why > not just use the session map to pass information > about, it will be passed to the @Persist and @Complete > annotated methods. For example: > > @Persist > private void persistMe(Map session) { > // use session here before serialization... > } > > @Complete > private void completeMe(Map session) { > // use the session here after serialization... > } > > This is just one way, there are tonnes of other ways > this can be done. > > Niall > > --- Ben Wolfe <si...@be...> wrote: > >> I can't seem to get the Replace method to work. >> I've attached a test >> method to demonstrate. Perhaps you can show me what >> I'm doing wrong. :-/ >> >> The @Replace/@Resolve methods have promise, but I >> still don't see a way >> for the person serializing to trigger it. The >> closest solution would be >> if "someProperty" in your example below were >> actually a global property >> set/retrieved via a call to a util class. However, >> our code is running >> on a server, and it is quite possible that multiple >> serializations will >> be happening at the same time -- some "primary key >> only" and some full. >> >> >public Object myResolveMethod() { >> > if(someProperty) { >> > return new SomeOtherObject(myProperty1, >> myProperty2); >> > } >> > return this; // Here I am saying don't read >> resolve >> >} >> >> I have coded up the tags possibility. I can submit >> a patch if you're >> interested. :-) >> >> Ben >> >> Niall Gallagher wrote: >>> Hi, >>> >>> Forgot to explain the following code snippit. This >>> demonstrates how an @Replace method could be used >>> instead of a @Resolve. The @Replace is used in >>> writing, it is similar to Java object >> serialization >>> writeReplace. >>> >>> @Root >>> public class SomeObject { >>> >>> @Element(required=false) >>> private String text; >>> >>> @Attribute(required=false) >>> private int version; >>> >>> @Attribute >>> private String key; >>> >>> public SomeObject() { >>> super(); >>> } >>> >>> public SomeObject(String key) { >>> this.key = key; >>> } >>> >>> @Validate >>> public void validate() { >>> // do some validation here... >>> } >>> >>> @Replace >>> private Object writeReplace() { >>> return new SomeObject(key); // Here I >> provide >>> the same type with a subset of the properties >>> } >>> } >>> >>> You could also use the @Persist and @Complete, the >>> method annotated with @Persist is called just >> before >>> serialization of the object, and @Complete is >> called >>> directly after. So you can modify the contents of >> the >>> object before it is serialized and bring the >> object >>> back to a known state when you have finished >>> serializing it. So you get a chance to modify the >>> object for serialization, there is an example in >> the >>> tutorial. >>> >>> Niall >>> >>> --- Niall Gallagher <gal...@ya...> >> wrote: >>>> Hi, >>>> >>>> This will give you both worlds. Why not do the >>>> following: >>>> >>>> public Object myResolveMethod() { >>>> if(someProperty) { >>>> return new SomeOtherObject(myProperty1, >>>> myProperty2); >>>> } >>>> return this; // Here I am saying don't read >>>> resolve >>>> } >>>> >>>> When you return "this" from the method annotated >>>> with >>>> @Resolve annotation you are saying not to resolve >> to >>>> something different. Also, you don't need to >> return >>>> a >>>> different type. >>>> >>>> >>>> @Root >>>> public class SomeObject { >>>> >>>> @Element(required=false) >>>> private String text; >>>> >>>> @Attribute(required=false) >>>> private int version; >>>> >>>> @Attribute >>>> private String key; >>>> >>>> public SomeObject() { >>>> super(); >>>> } >>>> >>>> public SomeObject(String key) { >>>> this.key = key; >>>> } >>>> >>>> @Validate >>>> public void validate() { >>>> // do some validation here... >>>> } >>>> >>>> @Replace >>>> private Object writeReplace() { >>>> return new SomeObject(key); // Here I >> provide >>>> the same type with a subset of the properties >>>> } >>>> } >>>> >>>> Hope this helps. >>>> >>>> Niall >>>> >>>> >>>> --- Ben Wolfe <si...@be...> wrote: >>>> >>>>> I'm not sure this will work for me. I want to >>>> have >>>>> both worlds. I want >>>>> to be able to serialize our objects to just >> their >>>>> primary keys sometimes >>>>> and at others be able to serialize all >>>> @Attributes, >>>>> @Elements, etc on >>>>> the object to xml. >>>>> >>>>> Ben >>>>> >>>>> Niall Gallagher wrote: >>>>>> Hi, >>>>>> >>>>>> There is a way you could do this, don't know >> how >>>>> well >>>>>> it would suit you. But the @Resolve and >> @Replace >>>>>> annotations are used in situations like this. >>>>> Anything >>>>>> you can do with the readResolve and >> writeReplace >>>>> for >>>>>> conventional object serialization can be done >>>> with >>>>>> these annotations. Here is an example of what >>>> you >>>>>> might do. >>>>>> >>>>>> >>>>>> @Root >>>>>> public class CompleteObject { >>>>>> >>>>>> @Attribute >>>>>> private String name; >>>>>> >>>>>> @Element > === message truncated ===> package > org.simpleframework.xml.load; >> import java.io.StringWriter; >> >> import org.simpleframework.xml.Attribute; >> import org.simpleframework.xml.Element; >> import org.simpleframework.xml.Root; >> import org.simpleframework.xml.ValidationTestCase; >> >> /** >> * >> */ >> public class ReplaceTest extends ValidationTestCase >> { >> >> private static final String exampleReplaceMethod >> = "<example exampleId=\"123\"/>"; >> >> @Root >> private static class Example { >> >> public Example(Integer exampleId) { >> this.exampleId = exampleId; >> } >> >> @Element(required=false) >> private String exampleMessage; >> >> @Attribute(required=false) >> private Integer exampleId; >> >> @Replace >> private Object exampleReplaceMethod() { >> return new Example(exampleId); >> } >> } >> >> /** >> * This method tests the replace method >> * >> * @throws Exception >> */ >> public void testReplaceExample() throws Exception { >> >> Persister persister = new Persister(); >> Example ex = new Example(123); >> ex.exampleMessage = "test"; >> >> StringWriter buffer = new StringWriter(); >> persister.write(ex, buffer); >> >> assertEquals("The serialization is not >> right.", exampleReplaceMethod, buffer.toString()); >> >> validate(ex, persister); >> >> } >> >> } > ------------------------------------------------------------------------- >> SF.Net email is sponsored by: >> 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 > > > > ____________________________________________________________________________________ > Never miss a thing. Make Yahoo your home page. > http://www.yahoo.com/r/hs |
|
From: Niall G. <gal...@ya...> - 2007-12-13 20:31:53
|
Hi,
I have just released version 1.6.1. The bug with
scattered elements has been resolved. Now all values
are set only after they have been fully read.
Niall
--- Filip Perlhagen <fil...@ev...>
wrote:
> Bug in scattered inlined elements:
> When using scattered inlined elements, the set(List
> list) method is called once only containing the
> first Element that is found. See the below test
> case:
>
> Possible fix: Call the set(List list) method only
> after alla element in the list has been added.
>
>
> import java.util.LinkedList;
> import java.util.List;
> import org.simpleframework.xml.Element;
> import org.simpleframework.xml.ElementList;
> import org.simpleframework.xml.Root;
> import org.simpleframework.xml.load.Persister;
>
> @Root(name="t")
> public class InlinePrimitiveList {
> public static boolean showBug;
>
> @Element String name;
> private List<String> data = new
> LinkedList<String>();
>
> @ElementList(inline=true)
> void setList(List<String> list) {
> if(showBug) {
> data = new LinkedList(list);
> } else {
> data = list;
> }
> }
>
> @ElementList(inline=true)
> List<String> getList() {
> return data;
> }
>
> public String toString() {
> return " name: " + name + " " + data;
> }
>
> public static void main(String[] args) throws
> Exception {
> showBug = false;
> test();
> showBug = true;
> test();
> }
>
> private static void test() throws Exception {
> System.out.println("Object: " + new
> Persister().read(InlinePrimitiveList.class,
>
"<t><string>1</string><name>a</name><string>2</string></t>"));
> }
>
> }
>
>
>
> /Filip Perlhagen
> >
-------------------------------------------------------------------------
> SF.Net email is sponsored by:
> 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
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|
|
From: Niall G. <gal...@ya...> - 2007-12-13 19:27:52
|
Hi Vladimir, For request 1, this should be possible. I had intended to revise this for 1.6 but did not get around to it. I will ensure that custom transforms are possible in an upcomming release. As for request 1, could you elaborate on what you are requesting here? Niall --- Vladimir <kov...@ma...> wrote: > I'd like to employ custom transformers for: > > 1. Field or property of type java.lang.Object > (Framework is able to serialize the field as > follows: > <my-field class="java.lang.String">value of > my-field</my-field> > It raises TransformException when deserializing.) > > 2. Third-party clases with read-only access. > > > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services > for just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ |
|
From: Vladimir <kov...@ma...> - 2007-12-12 11:56:41
|
I'd like to employ custom transformers for:
1. Field or property of type java.lang.Object
(Framework is able to serialize the field as follows:
<my-field class="java.lang.String">value of my-field</my-field>
It raises TransformException when deserializing.)
2. Third-party clases with read-only access.
|
|
From: Niall G. <gal...@ya...> - 2007-12-11 19:05:43
|
Hi Filip,
I was aware of this behaviour when using methods
instead of fields. I think your suggestion of adding
it only when all elements have finished seems
reasonable. Ill make sure to include this in the next
release.
Niall
--- Filip Perlhagen <fil...@ev...>
wrote:
> Bug in scattered inlined elements:
> When using scattered inlined elements, the set(List
> list) method is called once only containing the
> first Element that is found. See the below test
> case:
>
> Possible fix: Call the set(List list) method only
> after alla element in the list has been added.
>
>
> import java.util.LinkedList;
> import java.util.List;
> import org.simpleframework.xml.Element;
> import org.simpleframework.xml.ElementList;
> import org.simpleframework.xml.Root;
> import org.simpleframework.xml.load.Persister;
>
> @Root(name="t")
> public class InlinePrimitiveList {
> public static boolean showBug;
>
> @Element String name;
> private List<String> data = new
> LinkedList<String>();
>
> @ElementList(inline=true)
> void setList(List<String> list) {
> if(showBug) {
> data = new LinkedList(list);
> } else {
> data = list;
> }
> }
>
> @ElementList(inline=true)
> List<String> getList() {
> return data;
> }
>
> public String toString() {
> return " name: " + name + " " + data;
> }
>
> public static void main(String[] args) throws
> Exception {
> showBug = false;
> test();
> showBug = true;
> test();
> }
>
> private static void test() throws Exception {
> System.out.println("Object: " + new
> Persister().read(InlinePrimitiveList.class,
>
"<t><string>1</string><name>a</name><string>2</string></t>"));
> }
>
> }
>
>
>
> /Filip Perlhagen
> >
-------------------------------------------------------------------------
> SF.Net email is sponsored by:
> 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
>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
|