This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git


The following commit(s) were added to refs/heads/master by this push:
     new 64e7727  JOHNZON-351 support collection raw classes cast to Type in 
JSON-B Improve tests and case coverage
64e7727 is described below

commit 64e7727fee45344659028f6e8a814486086f03b7
Author: Jean-Louis Monteiro <jlmonte...@tomitribe.com>
AuthorDate: Tue Sep 21 11:20:10 2021 +0200

    JOHNZON-351 support collection raw classes cast to Type in JSON-B
    Improve tests and case coverage
    
    Signed-off-by: Jean-Louis Monteiro <jlmonte...@tomitribe.com>
---
 .../java/org/apache/johnzon/jsonb/JohnzonJsonb.java  |  4 ++--
 .../java/org/apache/johnzon/jsonb/JsonbReadTest.java | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git 
a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java 
b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
index bd9e9bc..69c4816 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
@@ -197,7 +197,7 @@ public class JohnzonJsonb implements Jsonb, AutoCloseable, 
JsonbExtension {
             } else if (JsonArray.class == runtimeType) {
                 return (T) delegate.readJsonArray(reader);
             } else if (isCollection(runtimeType)) {
-                return (T) delegate.readCollection(reader, 
ParameterizedType.class.cast(runtimeType));
+                return (T) delegate.readCollection(reader, 
toCollectionType(runtimeType));
             }
             final Type mappingType = unwrapPrimitiveOptional(runtimeType);
             final Object object = delegate.readObject(reader, mappingType);
@@ -240,7 +240,7 @@ public class JohnzonJsonb implements Jsonb, AutoCloseable, 
JsonbExtension {
             } else if (JsonArray.class == runtimeType) {
                 return (T) delegate.readJsonArray(stream);
             } else if (isCollection(runtimeType)) {
-                return (T) delegate.readCollection(stream, 
ParameterizedType.class.cast(runtimeType));
+                return (T) delegate.readCollection(stream, 
toCollectionType(runtimeType));
             }
 
             final Type mappingType = unwrapPrimitiveOptional(runtimeType);
diff --git 
a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbReadTest.java 
b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbReadTest.java
index 3ac7a48..8656416 100644
--- a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbReadTest.java
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbReadTest.java
@@ -30,6 +30,7 @@ import javax.json.bind.config.BinaryDataStrategy;
 import javax.json.bind.spi.JsonbProvider;
 
 import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.lang.reflect.Type;
 import java.nio.charset.StandardCharsets;
@@ -53,6 +54,25 @@ public class JsonbReadTest {
     }
 
     @Test
+    public void simpleArrayMappingReader() throws Exception {
+        final List<String> expectedResult = asList("Test String");
+        try (final Jsonb jsonb = JsonbBuilder.create()) {
+            final Object unmarshalledObject = jsonb.fromJson(new 
StringReader("[ \"Test String\" ]"), (Type) List.class);
+            assertEquals(expectedResult, unmarshalledObject);
+        }
+    }
+
+    @Test
+    public void simpleArrayMappingInputStream() throws Exception {
+        final List<String> expectedResult = asList("Test String");
+        try (final Jsonb jsonb = JsonbBuilder.create()) {
+            final Object unmarshalledObject = jsonb.fromJson(new 
ByteArrayInputStream("[ \"Test String\" ]".getBytes(
+                StandardCharsets.UTF_8)), (Type) List.class);
+            assertEquals(expectedResult, unmarshalledObject);
+        }
+    }
+
+    @Test
     public void boolFromString() {
         assertTrue(JsonbProvider.provider().create().build().fromJson("true", 
Boolean.class));
     }

Reply via email to