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

List.of for jdk >= 9 not deserialized OK

laurgarn opened this issue · comments

diff --git a/src/test/groovy/com/cedarsoftware/util/io/TestCollection.groovy b/src/test/groovy/com/cedarsoftware/util/io/TestCollection.groovy
index 7c3c51b..7284a9f 100644
--- a/src/test/groovy/com/cedarsoftware/util/io/TestCollection.groovy
+++ b/src/test/groovy/com/cedarsoftware/util/io/TestCollection.groovy
@@ -79,6 +79,8 @@ class TestCollection {
         private Set _strs_c;
         private Set _strs_d;
         private HashSet _typedSet;
+        private List<String> _imm_lst_0;
+        private List<String> _imm_lst_1;
 
         private void init() {
             Collection array = new ArrayList()
@@ -191,6 +193,10 @@ class TestCollection {
             _typedSet.add(true)
             _typedSet.add(17.76)
             _typedSet.add(TimeZone.getTimeZone("PST"))
+
+            _imm_lst_0 = List.of();
+            _imm_lst_1 = List.of("One");
+
         }
     }

causes :

com.cedarsoftware.util.io.JsonIoException: 
null
Last read: neInfo","zone":"PST"},{"@type":"java.math.BigDecimal","value":"17.76"},{"@type":"date","value":19},"string",true],"_imm_lst_0":{"@type":"java.util.ImmutableCollections$ListN"},"_imm_lst_1":{"@type":"java.util.ImmutableCollections$List12","@items":["One"]}}
line: 1, col: 3263
        at com.cedarsoftware.util.io.TestCollection.testReconstituteCollection2(TestCollection.groovy:366)
Caused by: java.lang.UnsupportedOperationException
        at com.cedarsoftware.util.io.TestCollection.testReconstituteCollection2(TestCollection.groovy:366)

Some tries/hints :
#176

json-io does not use List.of() in it's code base as it is JDK 1.8 compatible. Also, it does use aliases and classFactory entries to change the ImmutableList.ListN class to a SealableList() so that JDK 1.8 can read JSON written by JDK 1.9+.