This repository was archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
Deserializing with setSameNameLists(true) fails with JsonSyntaxException #25
Copy link
Copy link
Open
Description
Consider the following test case:
private static final String TEST_ACL_XML =
"<Class1>" +
" <Class2>" +
" <Class3/>" +
" </Class2>" +
"</Class1>";
@Test
public void testAclXml() {
Class1 acl = new GsonXmlBuilder()
.setXmlParserCreator(SimpleXmlReaderTest.PARSER_CREATOR)
.setSameNameLists(true)
.create()
.fromXml(TEST_ACL_XML, Class1.class);
}
static final class Class1 {
@SerializedName("Class2")
List<Class2> class2;
static final class Class2 {
@SerializedName("Class3")
Class3 class3;
static final class Class3 {
}
}
}which fails with:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: BEGIN_OBJECT expected, but met STRING
Scopes: INSIDE_OBJECT>NAME>INSIDE_OBJECT>INSIDE_EMBEDDED_ARRAY>INSIDE_OBJECT
Closed tags: 'Class3'/3
Token: null
Tokens queue: null
Values queue: , null
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:795)
at com.stanfy.gsonxml.GsonXml.fromXml(GsonXml.java:96)
at com.stanfy.gsonxml.GsonXml.fromXml(GsonXml.java:66)
at com.stanfy.gsonxml.GsonXml.fromXml(GsonXml.java:52)
at com.stanfy.gsonxml.GsonXml.fromXml(GsonXml.java:42)
at com.stanfy.gsonxml.test.ListsTest.testAclXml(ListsTest.java:303)
Removing setSameNameLists(true) allows the test to pass although my application requires this behavior.
Metadata
Metadata
Assignees
Labels
No labels