jdereg / json-io

Convert Java to JSON. Convert JSON to Java. Pretty print JSON. Java JSON serializer. Deep copy Java object graphs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception while deserializing `SingletonList`

Sekky61 opened this issue · comments

If this is known behavior, I suggest documenting it more clearly.
Note, that changing Collections.singletonList for List.of works without a problem.

Version: 4.14.1

Test for reproduction:

  @Test
  public void testSingletonListSerialization()
  {
    // Simple object with a list field, behaves the same with a class
    record Foo(List<String> list) { }
    
    // Serialize foo with a singletonList, then deserialization throws
    Foo    foo  = new Foo(Collections.singletonList("bar"));
    String json = JsonWriter.objectToJson(foo);
    // Problem is here:
    Assert.assertThrows(JsonIoException.class, () -> JsonReader.jsonToJava(json));
  }

This has been fixed and will be released in json-io 4.16.0.