[johnzon] branch master updated: minor fixes in reflection usage for JSON-B polymorphism (no functional change except complete meta support)
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 fcdd26e2 minor fixes in reflection usage for JSON-B polymorphism (no functional change except complete meta support) fcdd26e2 is described below commit fcdd26e2dcbdba51ef08d83f5a2c6606b12686f3 Author: Romain Manni-Bucau AuthorDate: Thu Apr 20 14:13:38 2023 +0200 minor fixes in reflection usage for JSON-B polymorphism (no functional change except complete meta support) --- johnzon-distribution/pom.xml | 10 ++-- .../polymorphism/JsonbPolymorphismHandler.java | 53 -- .../polymorphism/JsonbPolymorphismTypeInfo.java| 4 +- pom.xml| 4 +- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/johnzon-distribution/pom.xml b/johnzon-distribution/pom.xml index 69576e2b..e77d1ee5 100644 --- a/johnzon-distribution/pom.xml +++ b/johnzon-distribution/pom.xml @@ -161,7 +161,9 @@ +org.apache.maven.plugins maven-assembly-plugin +3.4.2 source-assembly @@ -203,14 +205,8 @@ org.apache.maven.plugins maven-jar-plugin - - -default-jar - - - - true + false diff --git a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/polymorphism/JsonbPolymorphismHandler.java b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/polymorphism/JsonbPolymorphismHandler.java index 5710ed0b..36f1aed5 100644 --- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/polymorphism/JsonbPolymorphismHandler.java +++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/polymorphism/JsonbPolymorphismHandler.java @@ -26,6 +26,8 @@ import jakarta.json.JsonValue; import jakarta.json.bind.JsonbException; import jakarta.json.bind.annotation.JsonbSubtype; import jakarta.json.bind.annotation.JsonbTypeInfo; + +import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -36,7 +38,7 @@ public class JsonbPolymorphismHandler { private final Map, JsonbPolymorphismTypeInfo> typeInfoCache = new HashMap<>(); public boolean hasPolymorphism(Class clazz) { -return clazz.isAnnotationPresent(JsonbTypeInfo.class) || getParentWithTypeInfo(clazz) != null; +return Meta.getAnnotation((AnnotatedElement) clazz, JsonbTypeInfo.class) != null || getParentWithTypeInfo(clazz) != null; } public Map.Entry[] getPolymorphismPropertiesToSerialize(Class clazz, Collection otherProperties) { @@ -47,8 +49,8 @@ public class JsonbPolymorphismHandler { // Only try to resolve types when there's a JsonbTypeInfo Annotation present on the current type, Meta.getAnnotation tries to // walk up parents by itself until it finds the given Annotation and could incorrectly cause JsonbExceptions to be thrown // (multiple JsonbTypeInfos with same key found even if thats not actually the case) -if (current.isAnnotationPresent(JsonbTypeInfo.class)) { -JsonbTypeInfo typeInfo = Meta.getAnnotation(current, JsonbTypeInfo.class); +JsonbTypeInfo typeInfo = Meta.getAnnotation((AnnotatedElement) current, JsonbTypeInfo.class); +if (typeInfo != null) { if (otherProperties.contains(typeInfo.key())) { throw new JsonbException("JsonbTypeInfo key '" + typeInfo.key() + "' collides with other properties in json"); } @@ -76,34 +78,38 @@ public class JsonbPolymorphismHandler { } public Class getTypeToDeserialize(JsonObject jsonObject, Class clazz) { -if (!typeInfoCache.containsKey(clazz)) { +JsonbPolymorphismTypeInfo typeInfo = typeInfoCache.get(clazz); +if (typeInfo == null) { return clazz; } -JsonbPolymorphismTypeInfo typeInfo = typeInfoCache.get(clazz); -if (!jsonObject.containsKey(typeInfo.getTypeKey())) { +JsonValue typeValue = jsonObject.get(typeInfo.getTypeKey()); +if (typeValue == null) { return clazz; } -JsonValue typeValue = jsonObject.get(typeInfo.getTypeKey()); if (typeValue.getValueType() != JsonValue.ValueType.STRING) { throw new JsonbException("Property '" + typeInfo.getTypeKey() + "' isn't a String, resolving JsonbSubtype is impossible"); } String typeValueString = ((JsonString) typeValue).getString(); -if (!typeInfo.getAliases().containsKey(typeValueString)) { +final Class result = typeInfo.getAliases().get(typeValueString); +if (result == null) { throw
[johnzon] branch master updated: Implement JSON-B 3 Polymorphism (#100)
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 9080e292 Implement JSON-B 3 Polymorphism (#100) 9080e292 is described below commit 9080e292749b5157cae0ad6b0e7c1de3a7ace275 Author: Markus Jung <54570207+ju...@users.noreply.github.com> AuthorDate: Thu Apr 20 13:54:34 2023 +0200 Implement JSON-B 3 Polymorphism (#100) * Implement JSON-B 3 polymorphism (WIP) * Implement more JSON-B 3 polymorphism validations * JSON-B 3 polymorphism tests * Allow JsonbSubtype for type=annotated type * MapperBuilder#setPolymorphismHandler javadoc * use JsonbRule in tests * Allow custom Mappings to be used * Implement JsonbMappings for polymorphism * create Mappings via Function instead of using reflection * use Meta.getAnnotation instead of Class.getAnnotation * restore old ClassMapping constructor for better backwards compatibility * update docs on jsonb-extras polymorphism * restore MapperConfig constructor * cache JsonbTypeInfos to avoid reflections --- .../org/apache/johnzon/jsonb/JohnzonBuilder.java | 9 +- .../org/apache/johnzon/jsonb/JsonbMappings.java| 74 .../polymorphism/JsonbPolymorphismHandler.java | 203 + .../polymorphism/JsonbPolymorphismTypeInfo.java| 46 + .../jsonb/polymorphism/JsonbPolymorphismTest.java | 92 ++ .../JsonbPolymorphismValidationTest.java | 143 +++ .../java/org/apache/johnzon/mapper/Mapper.java | 2 +- .../org/apache/johnzon/mapper/MapperBuilder.java | 10 +- .../org/apache/johnzon/mapper/MapperConfig.java| 13 +- .../johnzon/mapper/MappingGeneratorImpl.java | 29 +-- .../apache/johnzon/mapper/MappingParserImpl.java | 14 +- .../java/org/apache/johnzon/mapper/Mappings.java | 24 ++- .../org/apache/johnzon/mapper/access/Meta.java | 2 +- .../test/java/org/superbiz/ExtendMappingTest.java | 4 +- pom.xml| 4 +- src/site/markdown/index.md | 4 +- 16 files changed, 638 insertions(+), 35 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 4e32ed97..278e814a 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 @@ -31,6 +31,7 @@ import org.apache.johnzon.mapper.Converter; import org.apache.johnzon.mapper.Mapper; import org.apache.johnzon.mapper.MapperBuilder; import org.apache.johnzon.mapper.MapperConfig; +import org.apache.johnzon.mapper.Mappings; import org.apache.johnzon.mapper.ObjectConverter; import org.apache.johnzon.mapper.SerializeValueFilter; import org.apache.johnzon.mapper.access.AccessMode; @@ -58,6 +59,7 @@ import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Stream; @@ -336,6 +338,11 @@ public class JohnzonBuilder implements JsonbBuilder { if (Closeable.class.isInstance(accessMode)) { builder.addCloseable(Closeable.class.cast(accessMode)); } + + builder.setMappingsFactory(config.getProperty("johnzon.mappings-factory") +.map(it -> (Function) it) +.orElse(JsonbMappings::new)); + return doCreateJsonb(skipCdi, ijson, builder.build()); } @@ -469,4 +476,4 @@ public class JohnzonBuilder implements JsonbBuilder { protected abstract T doCreate(); } -} +} \ No newline at end of file diff --git a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbMappings.java b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbMappings.java new file mode 100644 index ..b399eb85 --- /dev/null +++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbMappings.java @@ -0,0 +1,74 @@ +/* + * 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
svn commit: r61385 - /release/johnzon/johnzon-1.2.20/
Author: jlmonteiro Date: Thu Apr 20 10:21:53 2023 New Revision: 61385 Log: Vote passed for Apache Johnzon 1.2.20 Added: release/johnzon/johnzon-1.2.20/ release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz (with props) release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.asc release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.sha512 release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip (with props) release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.asc release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.sha512 release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.tar.gz (with props) release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.tar.gz.asc release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.tar.gz.sha512 release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.zip (with props) release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.zip.asc release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-src.zip.sha512 Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz == Binary file - no diff available. Propchange: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz -- svn:mime-type = application/octet-stream Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.asc == --- release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.asc (added) +++ release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.asc Thu Apr 20 10:21:53 2023 @@ -0,0 +1,16 @@ +-BEGIN PGP SIGNATURE- + +iQIzBAABCgAdFiEEOUiCk4SyadMzzFuYNYgHxStLDiMFAmQPa+4ACgkQNYgHxStL +DiPEiQ/6Ar7ZQhvk3s/Z37Gh/9iEk7zIz9e70Chat1HEq05C7twmVbwG+611LDkC +4ZaBHP2/4M6SVPtchvdlB57KORDMd1eqY8B9rbRqmpa4ppe4NhxqEv+7KWRT7gqA +r6iATgJECVtst0Lk8sjgPsXjsVY2G899F8L/v92BHhQ5iIrA/BHkhf4X6TC/uIfy +8pgsmEeDxGyHssysMZFkEVlel04q5EaHlHPlAMfZN3bWdPwe1CxIZIT5RbgquEcp +TZUvjxPxusBFRFsSgYqBXlIfg72Evpt5y/G4beWHFWV7FfNMwzKgMmiGa0jyE+4N +Oau1XJT0RF0XLusItXAMnPdVcVBpGj/Q5z7oZuxNscufYg6+J7JsqOFwSqfiKz/D +KAvuQT0U2tiQq9hDDzrlmTK3HP0xjzDsR5WzGviEczVabxTvSEhbQxgDLVNv2JTO +tCR6JS4cwnea6koxAam21oopUYDJoTQNVxddfykAR0fbZ/5iTgepksaGR5oaDkYO +ch9vqJ9Ou8+DY16cFtWnFKrMPinNQUfqzgVG6JPShqYZM0I7nvyaWTJllHXel3aR +huD+bvqPBnuDEmhB5zs2ncZLpm1UahZLC70+bKPVo6AhAwAwX9gZH4xjIwstG7MD +7MoxMJQADRDTX+MbrEUQhHRwbnNZ/Vz2W8q7UzliSTrKltNzVm4= +=PXK4 +-END PGP SIGNATURE- Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.sha512 == --- release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.sha512 (added) +++ release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.tar.gz.sha512 Thu Apr 20 10:21:53 2023 @@ -0,0 +1 @@ +202e6465307d156ffca3e28331902681bb5fc2885462cc894de680c2cfb1b6b88f911fa5358bf3081a5e4ac6da1746d3975779c064af8767113b0cb385cbf079 apache-johnzon-1.2.20-bin.tar.gz Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip == Binary file - no diff available. Propchange: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip -- svn:mime-type = application/octet-stream Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.asc == --- release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.asc (added) +++ release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.asc Thu Apr 20 10:21:53 2023 @@ -0,0 +1,16 @@ +-BEGIN PGP SIGNATURE- + +iQIzBAABCgAdFiEEOUiCk4SyadMzzFuYNYgHxStLDiMFAmQPa+4ACgkQNYgHxStL +DiNXtQ//aiUUQQF0mLD8n0XHJuMhkLAR088OdJ2XOQ/ulm8h0GSEaFyvDq2get6v +qgTMf4cx+FxTqQhk2wtLWTzlh6gDIbNzDcJR48JED85jeq9d9QGG/GwKg6c3o3/r +a663/MwiRv3ZRSdkrypH2r3WWLTLP10TkQWDGmx/9RLPycterytznaYT+cfi3Rr+ +RCHOVSRhrqhx23cSk8ann4o/kHF5n7OSAvFm4OUn9nAINPoj+q5t/gIpYD5y+xXU +xlHXjcW0ym4tC6T7FhIEoQFIHC4evt01ak5hwlguIvzux5tdyUQYF3DZ8QTf2TMF +Kkmyikp6lytyab3qQvvvmmuRLk1MQgZlqLI29o6JTxVk0eKJvuxC8aBzdjXfT/wc +EdJh1tg34TdyWfk+7t7KVh4CJlZ6n7kmcV13f8tMnYCOI72bmDMnL3ibGWFZbAwz ++lk9V8ugWb6Uv+AoRkJt/bt8ScPdSnE627oiOlG3iMeZJnSMtmjdeT5wZs04srAT +E4HPQor3bJAwspUmrSlwQYrxZij1D14tlvUTI/mVuqH8p99il96V3VeCEM74upu7 +yWoj0CkDwSm2dzfXrCjjAiBFodvAU0ty5l0E9xjsYttLZZ4gLl5FjXwGVal6NJtU +EPOkHh/u5z4iKQRKZfn07VzOzhkjFgatWNZXTkG6+zXc1YOptzM= +=kCLN +-END PGP SIGNATURE- Added: release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.sha512 == --- release/johnzon/johnzon-1.2.20/apache-johnzon-1.2.20-bin.zip.sha512 (added) +++
svn commit: r61386 - /dev/johnzon/johnzon-1.2.20/
Author: jlmonteiro Date: Thu Apr 20 10:22:05 2023 New Revision: 61386 Log: Vote passed for Apache Johnzon 1.2.20 Removed: dev/johnzon/johnzon-1.2.20/