Re: [Simple-support] ignored name attribute of Root annotation
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-05-04 14:15:19
|
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
|