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 2016/01/29 23:04:26 UTC
incubator-johnzon git commit: removing @JsonbValue
Repository: incubator-johnzon
Updated Branches:
refs/heads/master e3cb0c026 -> 093f095d2
removing @JsonbValue
Project: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/commit/093f095d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/tree/093f095d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/diff/093f095d
Branch: refs/heads/master
Commit: 093f095d28e0503271449b7acbd5165071695294
Parents: e3cb0c0
Author: Romain Manni-Bucau <rm...@gmail.org>
Authored: Fri Jan 29 23:04:18 2016 +0100
Committer: Romain Manni-Bucau <rm...@gmail.org>
Committed: Fri Jan 29 23:04:18 2016 +0100
----------------------------------------------------------------------
.../apache/johnzon/jsonb/JsonbAccessMode.java | 19 +++++-------
.../jsonb/converter/JohnzonJsonbAdapter.java | 6 ++++
.../javax/json/bind/adapter/JsonbAdapter.java | 5 ++-
.../javax/json/bind/annotation/JsonbValue.java | 32 --------------------
4 files changed, 17 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/093f095d/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbAccessMode.java
----------------------------------------------------------------------
diff --git a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbAccessMode.java b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbAccessMode.java
index 0dbdd29..083be42 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbAccessMode.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JsonbAccessMode.java
@@ -44,7 +44,6 @@ import javax.json.bind.annotation.JsonbProperty;
import javax.json.bind.annotation.JsonbPropertyOrder;
import javax.json.bind.annotation.JsonbTransient;
import javax.json.bind.annotation.JsonbTypeAdapter;
-import javax.json.bind.annotation.JsonbValue;
import javax.json.bind.config.PropertyNamingStrategy;
import javax.json.bind.config.PropertyOrderStrategy;
import javax.json.bind.config.PropertyVisibilityStrategy;
@@ -149,12 +148,11 @@ public class JsonbAccessMode implements AccessMode, Closeable {
final JsonbTypeAdapter adapter = parameter.getAnnotation(JsonbTypeAdapter.class);
final JsonbDateFormat dateFormat = parameter.getAnnotation(JsonbDateFormat.class);
final JsonbNumberFormat numberFormat = parameter.getAnnotation(JsonbNumberFormat.class);
- final JsonbValue value = parameter.getAnnotation(JsonbValue.class);
- if (adapter == null && dateFormat == null && numberFormat == null && value == null) {
+ if (adapter == null && dateFormat == null && numberFormat == null) {
converters[i] = defaultConverters.get(parameter.getType());
itemConverters[i] = null;
} else {
- validateAnnotations(parameter, adapter, dateFormat, numberFormat, value);
+ validateAnnotations(parameter, adapter, dateFormat, numberFormat);
try {
final Adapter converter = toConverter(parameter.getType(), adapter, dateFormat, numberFormat);
@@ -253,11 +251,10 @@ public class JsonbAccessMode implements AccessMode, Closeable {
private void validateAnnotations(final Object parameter,
final JsonbTypeAdapter adapter, final JsonbDateFormat dateFormat,
- final JsonbNumberFormat numberFormat, final JsonbValue value) {
+ final JsonbNumberFormat numberFormat) {
int notNull = adapter != null ? 1 : 0;
notNull += dateFormat != null ? 1 : 0;
notNull += numberFormat != null ? 1 : 0;
- notNull += value != null ? 1 : 0;
if (notNull > 1) {
throw new IllegalArgumentException("Conflicting @JsonbXXX on " + parameter);
}
@@ -335,12 +332,11 @@ public class JsonbAccessMode implements AccessMode, Closeable {
final JsonbTypeAdapter adapter = initialReader.getAnnotation(JsonbTypeAdapter.class);
final JsonbDateFormat dateFormat = initialReader.getAnnotation(JsonbDateFormat.class);
final JsonbNumberFormat numberFormat = initialReader.getAnnotation(JsonbNumberFormat.class);
- final JsonbValue jsonbValue = initialReader.getAnnotation(JsonbValue.class);
- validateAnnotations(initialReader, adapter, dateFormat, numberFormat, jsonbValue);
+ validateAnnotations(initialReader, adapter, dateFormat, numberFormat);
final Adapter<?, ?> converter;
try {
- converter = adapter == null && dateFormat == null && numberFormat == null && jsonbValue == null ?
+ converter = adapter == null && dateFormat == null && numberFormat == null ?
defaultConverters.get(new AdapterKey(initialReader.getType(), String.class)) :
toConverter(initialReader.getType(), adapter, dateFormat, numberFormat);
} catch (final InstantiationException | IllegalAccessException e) {
@@ -437,12 +433,11 @@ public class JsonbAccessMode implements AccessMode, Closeable {
final JsonbTypeAdapter adapter = initialWriter.getAnnotation(JsonbTypeAdapter.class);
final JsonbDateFormat dateFormat = initialWriter.getAnnotation(JsonbDateFormat.class);
final JsonbNumberFormat numberFormat = initialWriter.getAnnotation(JsonbNumberFormat.class);
- final JsonbValue jsonbValue = initialWriter.getAnnotation(JsonbValue.class);
- validateAnnotations(initialWriter, adapter, dateFormat, numberFormat, jsonbValue);
+ validateAnnotations(initialWriter, adapter, dateFormat, numberFormat);
final Adapter<?, ?> converter;
try {
- converter = adapter == null && dateFormat == null && numberFormat == null && jsonbValue == null ?
+ converter = adapter == null && dateFormat == null && numberFormat == null ?
defaultConverters.get(new AdapterKey(initialWriter.getType(), String.class)) :
toConverter(initialWriter.getType(), adapter, dateFormat, numberFormat);
} catch (final InstantiationException | IllegalAccessException e) {
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/093f095d/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/converter/JohnzonJsonbAdapter.java
----------------------------------------------------------------------
diff --git a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/converter/JohnzonJsonbAdapter.java b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/converter/JohnzonJsonbAdapter.java
index 08e5a72..02d9437 100644
--- a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/converter/JohnzonJsonbAdapter.java
+++ b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/converter/JohnzonJsonbAdapter.java
@@ -32,6 +32,9 @@ public class JohnzonJsonbAdapter<A, B> implements Adapter<A, B> {
@Override
public A to(final B obj) {
+ if (obj == null && !delegate.handlesNullValue()) {
+ return null;
+ }
try {
return delegate.adaptTo(obj);
} catch (final Exception e) {
@@ -41,6 +44,9 @@ public class JohnzonJsonbAdapter<A, B> implements Adapter<A, B> {
@Override
public B from(final A obj) {
+ if (obj == null && !delegate.handlesNullValue()) {
+ return null;
+ }
try {
return delegate.adaptFrom(obj);
} catch (final Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/093f095d/jsonb-api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java
----------------------------------------------------------------------
diff --git a/jsonb-api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java b/jsonb-api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java
index 05221ac..4139b67 100644
--- a/jsonb-api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java
+++ b/jsonb-api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java
@@ -18,8 +18,11 @@
*/
package javax.json.bind.adapter;
-// under discussion
public interface JsonbAdapter<A, B> {
A adaptTo(B obj) throws Exception;
B adaptFrom(A obj) throws Exception;
+ default boolean handlesNullValue() {
+ return false;
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/093f095d/jsonb-api/src/main/java/javax/json/bind/annotation/JsonbValue.java
----------------------------------------------------------------------
diff --git a/jsonb-api/src/main/java/javax/json/bind/annotation/JsonbValue.java b/jsonb-api/src/main/java/javax/json/bind/annotation/JsonbValue.java
deleted file mode 100644
index 7b44286..0000000
--- a/jsonb-api/src/main/java/javax/json/bind/annotation/JsonbValue.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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 javax.json.bind.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@JsonbAnnotation
-@Retention(RetentionPolicy.RUNTIME)
-@Target({
- ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER
-})
-public @interface JsonbValue {
-}