37
37
* {@link UnsupportedOperationException} when calling modifying methods.
38
38
*
39
39
* @author Mark Paluch
40
+ * @author Peter-Josef Meisch
40
41
* @since 4.0
41
42
*/
42
43
public interface Document extends Map <String , Object > {
@@ -53,7 +54,7 @@ static Document create() {
53
54
/**
54
55
* Create a {@link Document} from a {@link Map} containing key-value pairs and sub-documents.
55
56
*
56
- * @param map source map containing key-value pairs and sub-documents.
57
+ * @param map source map containing key-value pairs and sub-documents. must not be {@literal null}.
57
58
* @return a new {@link Document}.
58
59
*/
59
60
static Document from (Map <String , Object > map ) {
@@ -74,6 +75,9 @@ static Document from(Map<String, Object> map) {
74
75
* @return the parsed {@link Document}.
75
76
*/
76
77
static Document parse (String json ) {
78
+
79
+ Assert .notNull (json , "JSON must not be null" );
80
+
77
81
try {
78
82
return new MapDocument (MapDocument .OBJECT_MAPPER .readerFor (Map .class ).readValue (json ));
79
83
} catch (IOException e ) {
@@ -84,11 +88,14 @@ static Document parse(String json) {
84
88
/**
85
89
* {@link #put(Object, Object)} the {@code key}/{@code value} tuple and return {@code this} {@link Document}.
86
90
*
87
- * @param key key with which the specified value is to be associated.
91
+ * @param key key with which the specified value is to be associated. must not be {@literal null}.
88
92
* @param value value to be associated with the specified key.
89
93
* @return {@code this} {@link Document}.
90
94
*/
91
95
default Document append (String key , Object value ) {
96
+
97
+ Assert .notNull (key , "Key must not be null" );
98
+
92
99
put (key , value );
93
100
return this ;
94
101
}
@@ -369,12 +376,15 @@ default String getStringOrDefault(String key, Supplier<String> defaultValue) {
369
376
* <p>
370
377
* Any exception thrown by the function will be propagated to the caller.
371
378
*
372
- * @param transformer functional interface to a apply
379
+ * @param transformer functional interface to a apply. must not be {@literal null}.
373
380
* @param <R> class of the result
374
381
* @return the result of applying the function to this string
375
382
* @see java.util.function.Function
376
383
*/
377
384
default <R > R transform (Function <? super Document , ? extends R > transformer ) {
385
+
386
+ Assert .notNull (transformer , "transformer must not be null" );
387
+
378
388
return transformer .apply (this );
379
389
}
380
390
0 commit comments