[johnzon] branch master updated: checkstyle fix

2022-07-19 Thread rmannibucau
This is an automated email from the ASF dual-hosted git repository.

rmannibucau 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 f655ae33 checkstyle fix
f655ae33 is described below

commit f655ae33f7fe56136ee2f04a5c62f0728559591f
Author: Romain Manni-Bucau 
AuthorDate: Tue Jul 19 13:42:03 2022 +0200

checkstyle fix
---
 .../src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java  | 1 -
 .../src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java| 2 +-
 .../src/test/java/org/apache/johnzon/jsonb/test/JsonbRule.java  | 1 -
 3 files changed, 1 insertion(+), 3 deletions(-)

diff --git 
a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java 
b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
index bbeb2d46..400dfcfa 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
@@ -55,7 +55,6 @@ import java.io.Closeable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
diff --git 
a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java 
b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java
index e690f211..256f855a 100644
--- a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java
@@ -32,7 +32,7 @@ public class JsonbAdapterTest {
 public JsonbRule jsonbRule = new JsonbRule().withTypeAdapter(new 
ColorIdAdapter());
 
 @Test
-public void test_inherited_adapter_recognized() {
+public void testInheritedAdapterRecognized() {
 // given
 ColorId colorId = new ColorId("#336699");
 
diff --git 
a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/test/JsonbRule.java 
b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/test/JsonbRule.java
index 43575ed4..62779863 100644
--- a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/test/JsonbRule.java
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/test/JsonbRule.java
@@ -18,7 +18,6 @@
  */
 package org.apache.johnzon.jsonb.test;
 
-import org.apache.johnzon.jsonb.JsonbAdapterTest;
 import org.apache.johnzon.jsonb.api.experimental.JsonbExtension;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;



[johnzon] branch master updated: [JOHNZON-386] Make JsonbAdapter inheritable

2022-07-19 Thread rmannibucau
This is an automated email from the ASF dual-hosted git repository.

rmannibucau 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 6b106280 [JOHNZON-386] Make JsonbAdapter inheritable
 new a6ae280c Merge pull request #92 from 
bmarwell/JOHNZON-386_inherited_jsonbadapter
6b106280 is described below

commit 6b106280436466fe7b920a97c774075b98d34832
Author: Benjamin Marwell 
AuthorDate: Tue Jul 19 12:32:15 2022 +0200

[JOHNZON-386] Make JsonbAdapter inheritable

Co-authored-by: Romain Manni-Bucau 
---
 .../org/apache/johnzon/jsonb/JohnzonBuilder.java   | 15 ++--
 .../org/apache/johnzon/jsonb/JsonbAdapterTest.java | 79 ++
 .../org/apache/johnzon/jsonb/test/JsonbRule.java   |  8 +++
 3 files changed, 92 insertions(+), 10 deletions(-)

diff --git 
a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java 
b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
index 2e2f2a48..bbeb2d46 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java
@@ -55,13 +55,9 @@ import java.io.Closeable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
@@ -238,10 +234,10 @@ public class JohnzonBuilder implements JsonbBuilder {
 .ifPresent(builder::setSnippetMaxLength);
 
 // user adapters
+final Types types = new Types();
+
 config.getProperty(JsonbConfig.ADAPTERS).ifPresent(adapters -> 
Stream.of(JsonbAdapter[].class.cast(adapters)).forEach(adapter -> {
-final ParameterizedType pt = ParameterizedType.class.cast(
-Stream.of(adapter.getClass().getGenericInterfaces())
-  .filter(i -> ParameterizedType.class.isInstance(i) 
&& ParameterizedType.class.cast(i).getRawType() == 
JsonbAdapter.class).findFirst().orElse(null));
+final ParameterizedType pt = 
types.findParameterizedType(adapter.getClass(), JsonbAdapter.class);
 if (pt == null) {
 throw new IllegalArgumentException(adapter + " doesn't 
implement JsonbAdapter");
 }
@@ -286,7 +282,6 @@ public class JohnzonBuilder implements JsonbBuilder {
 getBeanManager(); // force detection
 }
 
-final Types types = new Types();
 builder.setReadAttributeBeforeWrite(
 
config.getProperty("johnzon.readAttributeBeforeWrite").map(Boolean.class::cast).orElse(false));
 builder.setAutoAdjustStringBuffers(
diff --git 
a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java 
b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java
new file mode 100644
index ..e690f211
--- /dev/null
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.jsonb;
+
+import org.apache.johnzon.jsonb.test.JsonbRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import javax.json.bind.adapter.JsonbAdapter;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonbAdapterTest {
+
+@Rule
+public JsonbRule jsonbRule = new JsonbRule().withTypeAdapter(new 
ColorIdAdapter());
+
+@Test
+public void test_inherited_adapter_recognized() {
+// given
+ColorId colorId = new ColorId("#336699");
+
+// when
+String json = jsonbRule.toJson(colorId);
+
+// then
+assertEquals("\"#336699\"", json);
+}
+
+interface ValueType {
+T value();
+}
+
+static class