[Simple-support] ignored name attribute of Root annotation
Brought to you by:
niallg
|
From: Adam R. <ada...@gm...> - 2012-05-04 08:27:05
|
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
|