Re: [Simple-support] ignored name attribute of Root annotation
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-05-05 04:03:09
|
You could do a number of things, for example you could extend the Persister and override the method taking the InputNode, here you could check the root node name. You could also use a Visitor, and check it there with the InputNode. Another way is a Strategy, but this is pretty much the same as a Visitor with a few more complications.
--- On Fri, 4/5/12, Adam Ruka <ada...@gm...> wrote:
From: Adam Ruka <ada...@gm...>
Subject: Re: [Simple-support] ignored name attribute of Root annotation
To: sim...@li...
Received: Friday, 4 May, 2012, 1:18 PM
Hi,
that's reasonable, altough it doesn't solve my problem, which is: how to force the XML root element to have a specific name? In other words, what changes have to be made to the RootEl class to make that third test that I posted earlier fail?
On Fri, May 4, 2012 at 4:15 PM, Niall Gallagher <gal...@ya...> wrote:
Hi,
Yes this is true, this is an intentional feature. You need to be able to override the name of an entry within a list. This allows each element to override the name of the entry.
Niall
--- On Fri, 4/5/12, Adam Ruka <ada...@gm...> wrote:
From: Adam Ruka <ada...@gm...>
Subject: [Simple-support] ignored name attribute of Root annotation
To: sim...@li...
Received: Friday, 4 May, 2012, 1:26 AM
Hello everybody,
first of all, I want to say that Simple is the best XML library I've
ever used. I absolutely love it. Having said that, I stumbled upon
some weird behavior lately: the name attribute of
the Root annotation
seems to be ignored when deserializing XML to an object. Here is a
small test case which illustrates the problem:
import static org.junit.Assert.*;
import org.junit.Test;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.PersistenceException;
import org.simpleframework.xml.core.Persister;
public class BadRootNameTest {
private static final Serializer persister = new Persister();
@Root(name="root")
public static class RootEl {
@Attribute
public String attr;
}
@Test
public void
testGoodRoot() throws Exception {
// passes OK
RootEl rootEl = persister.read(RootEl.class, "<root
attr=\"xxx\"/>");
assertNotNull(rootEl);
assertEquals("xxx", rootEl.attr);
}
@Test(expected=PersistenceException.class)
public void testBadAttr() throws Exception {
// throws an exception, as is expected
persister.read(RootEl.class, "<root xxx=\"yyyy\"/>");
}
@Test
public void testBadRootName() throws
Exception {
// does NOT throw an exception!
RootEl rootEl = persister.read(RootEl.class,
"<xxxxxxxxxx attr=\"yyy\"/>");
assertNotNull(rootEl);
assertEquals("yyy", rootEl.attr);
}
}
I believe the same thing happens with the ElementList annotation when
inline is set to false. Is this a bug, or do you need to do something
special for the name attribute to take effect? Thanks in advance for
any help.
Best wishes,
Adam Ruka
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT
managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|