Skip to content

Commit dea2d2c

Browse files
authored
Merge pull request #194 from mkarg/GH-193
GH-193 May adapter input / output be null?
2 parents b29bc1e + 63b34d9 commit dea2d2c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -71,8 +71,8 @@ public interface JsonbAdapter<Original, Adapted> {
7171
* After conversion Adapted type will be mapped to JSON the standard way.
7272
*
7373
* @param obj
74-
* Object to convert.
75-
* @return Converted object which will be serialized to JSON.
74+
* Object to convert or {@code null}.
75+
* @return Converted object which will be serialized to JSON or {@code null}.
7676
* @throws Exception if there is an error during the conversion.
7777
*/
7878
Adapted adaptToJson(Original obj) throws Exception;
@@ -81,8 +81,8 @@ public interface JsonbAdapter<Original, Adapted> {
8181
* This method is used on deserialization only. It contains a conversion logic from type Adapted to type Original.
8282
*
8383
* @param obj
84-
* Object to convert.
85-
* @return Converted object representing pojo to be set into object graph.
84+
* Object to convert or {@code null}.
85+
* @return Converted object representing pojo to be set into object graph or {@code null}.
8686
* @throws Exception if there is an error during the conversion.
8787
*/
8888
Original adaptFromJson(Adapted obj) throws Exception;

docs/src/docs/user-guide.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ public class CustomerAnnotated {
515515
public class CustomerAdapter implements JsonbAdapter<Customer, CustomerAnnotated> {
516516
@Override
517517
public CustomerAnnotated adaptToJson(Customer c) throws Exception {
518+
if (c == null)
519+
return null;
518520
CustomerAnnotated customer = new Customer();
519521
customer.setId(c.getId());
520522
customer.setName(c.getName());
@@ -523,6 +525,8 @@ public class CustomerAdapter implements JsonbAdapter<Customer, CustomerAnnotated
523525
524526
@Override
525527
public Customer adaptFromJson(CustomerAnnotated adapted) throws Exception {
528+
if (adapted == null)
529+
return null;
526530
Customer customer = new Customer();
527531
customer.setId(adapted.getId());
528532
customer.setName(adapted.getName());

0 commit comments

Comments
 (0)