Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Deserializing with setSameNameLists(true) fails with JsonSyntaxException #25

Open
gaul opened this issue Jan 19, 2016 · 3 comments
Open

Comments

@gaul
Copy link
Contributor

gaul commented Jan 19, 2016

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.

@TeemuStenhammar
Copy link

I am having this same issue with nested object. Is there any plan to look in to this?

@gaul
Copy link
Contributor Author

gaul commented Apr 20, 2016

@TeemuStenhammar I moved to jackson-dataformat-xml since this issue blocked me.

@TeemuStenhammar
Copy link

@andrewgaul Thank you for pointing to that project! Just switched to it and after a bit configuration I got forward from this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants