You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by rm...@apache.org on 2018/03/27 13:48:12 UTC
[11/12] johnzon git commit: atomic jsonb supplier
atomic jsonb supplier
Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/2e4a6aeb
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/2e4a6aeb
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/2e4a6aeb
Branch: refs/heads/master
Commit: 2e4a6aeb412306f1bb328945cb51d9dca434c8ac
Parents: 293e40c
Author: amoscatelli <al...@live.com>
Authored: Tue Mar 27 15:27:49 2018 +0200
Committer: amoscatelli <al...@live.com>
Committed: Tue Mar 27 15:27:49 2018 +0200
----------------------------------------------------------------------
.../jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/johnzon/blob/2e4a6aeb/johnzon-jsonb/src/main/java/org/apache/johnzon/jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java
----------------------------------------------------------------------
diff --git a/johnzon-jsonb/src/main/java/org/apache/johnzon/jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java b/johnzon-jsonb/src/main/java/org/apache/johnzon/jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java
index 6b76b6f..15e1194 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jaxrs/jsonb/jaxrs/JsonbJaxrsProvider.java
@@ -43,6 +43,7 @@ import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
import javax.annotation.Priority;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.ContextResolver;
@@ -56,7 +57,7 @@ import javax.ws.rs.ext.Providers;
public class JsonbJaxrsProvider<T> implements MessageBodyWriter<T>, MessageBodyReader<T> {
protected final Collection<String> ignores;
- protected final AtomicReference<Jsonb> delegate = new AtomicReference<>();
+ protected final AtomicReference<Supplier<Jsonb>> delegate = new AtomicReference<>();
protected final JsonbConfig config = new JsonbConfig();
@Context
@@ -69,7 +70,7 @@ public class JsonbJaxrsProvider<T> implements MessageBodyWriter<T>, MessageBodyR
protected JsonbJaxrsProvider(final Collection<String> ignores) {
this.ignores = ignores;
}
-
+
protected Jsonb createJsonb() {
return JsonbBuilder.create(config);
}
@@ -164,14 +165,14 @@ public class JsonbJaxrsProvider<T> implements MessageBodyWriter<T>, MessageBodyR
}
protected Jsonb getJsonb(Class<?> type) {
- ContextResolver<Jsonb> contextResolver = providers.getContextResolver(Jsonb.class, MediaType.APPLICATION_JSON_TYPE);
- if (contextResolver != null) {
- return contextResolver.getContext(type);
- } else {
- if (delegate.get() == null) {
- delegate.compareAndSet(null, createJsonb());
+ if (delegate.get() == null){
+ ContextResolver<Jsonb> contextResolver = providers.getContextResolver(Jsonb.class, MediaType.APPLICATION_JSON_TYPE);
+ if (contextResolver != null) {
+ delegate.compareAndSet(null, ()-> contextResolver.getContext(type));
+ } else {
+ delegate.compareAndSet(null, ()-> createJsonb());
}
- return delegate.get();
}
+ return delegate.get().get();
}
}