2929import java .util .function .Supplier ;
3030import java .util .function .UnaryOperator ;
3131
32+ import org .jspecify .annotations .NonNull ;
3233import org .jspecify .annotations .Nullable ;
3334
3435import org .springframework .boot .json .JsonValueWriter .Series ;
@@ -118,9 +119,9 @@ default JsonWriter<T> withNewLineAtEnd() {
118119 * Return a new {@link JsonWriter} instance that appends the given suffix after the
119120 * JSON has been written.
120121 * @param suffix the suffix to write, if any
121- * @return a new {@link JsonWriter} instance that appends a suffixafter the JSON
122+ * @return a new {@link JsonWriter} instance that appends a suffix after the JSON
122123 */
123- default JsonWriter <T > withSuffix (String suffix ) {
124+ default JsonWriter <T > withSuffix (@ Nullable String suffix ) {
124125 if (!StringUtils .hasLength (suffix )) {
125126 return this ;
126127 }
@@ -221,7 +222,7 @@ public <V> Member<V> add(String name, @Nullable V value) {
221222 * @param supplier a supplier of the value
222223 * @return the added {@link Member} which may be configured further
223224 */
224- public <V > Member <V > add (String name , Supplier <V > supplier ) {
225+ public <V > Member <V > add (String name , Supplier <@ Nullable V > supplier ) {
225226 Assert .notNull (supplier , "'supplier' must not be null" );
226227 return add (name , (instance ) -> supplier .get ());
227228 }
@@ -233,7 +234,7 @@ public <V> Member<V> add(String name, Supplier<V> supplier) {
233234 * @param extractor {@link Extractor} to extract the value
234235 * @return the added {@link Member} which may be configured further
235236 */
236- public <V > Member <V > add (String name , Extractor <T , ? extends @ Nullable V > extractor ) {
237+ public <V > Member <V > add (String name , Extractor <T , V > extractor ) {
237238 Assert .notNull (name , "'name' must not be null" );
238239 Assert .notNull (extractor , "'extractor' must not be null" );
239240 return addMember (name , extractor );
@@ -268,7 +269,7 @@ public <M extends Map<K, V>, K, V> Member<M> addMapEntries(Extractor<T, M> extra
268269 * @param value the member value
269270 * @return the added {@link Member} which may be configured further
270271 */
271- public <V > Member <V > from (V value ) {
272+ public <V > Member <V > from (@ Nullable V value ) {
272273 return from ((instance ) -> value );
273274 }
274275
@@ -279,7 +280,7 @@ public <V> Member<V> from(V value) {
279280 * @param supplier a supplier of the value
280281 * @return the added {@link Member} which may be configured further
281282 */
282- public <V > Member <V > from (Supplier <V > supplier ) {
283+ public <V > Member <V > from (Supplier <@ Nullable V > supplier ) {
283284 Assert .notNull (supplier , "'supplier' must not be null" );
284285 return from ((instance ) -> supplier .get ());
285286 }
@@ -323,7 +324,7 @@ public void applyingValueProcessor(ValueProcessor<?> valueProcessor) {
323324 this .jsonProcessors .valueProcessors ().add (valueProcessor );
324325 }
325326
326- private <V > Member <V > addMember (@ Nullable String name , Extractor <T , ? extends @ Nullable V > extractor ) {
327+ private <V > Member <V > addMember (@ Nullable String name , Extractor <T , V > extractor ) {
327328 Member <V > member = new Member <>(this .members .size (), name , ValueExtractor .of (extractor ));
328329 this .members .add (member );
329330 return member ;
@@ -396,7 +397,7 @@ public Member<T> whenNotNull() {
396397 * @param extractor an function used to extract the value to test
397398 * @return a {@link Member} which may be configured further
398399 */
399- public Member <T > whenNotNull (Function <T , ?> extractor ) {
400+ public Member <T > whenNotNull (Function <@ Nullable T , ?> extractor ) {
400401 Assert .notNull (extractor , "'extractor' must not be null" );
401402 return when ((instance ) -> Objects .nonNull (extractor .apply (instance )));
402403 }
@@ -417,15 +418,16 @@ public Member<T> whenHasLength() {
417418 * @return a {@link Member} which may be configured further
418419 */
419420 public Member <T > whenNotEmpty () {
420- return whenNot (ObjectUtils ::isEmpty );
421+ Predicate <@ Nullable T > isEmpty = ObjectUtils ::isEmpty ;
422+ return whenNot (isEmpty );
421423 }
422424
423425 /**
424426 * Only include this member when the given predicate does not match.
425427 * @param predicate the predicate to test
426428 * @return a {@link Member} which may be configured further
427429 */
428- public Member <T > whenNot (Predicate <T > predicate ) {
430+ public Member <T > whenNot (Predicate <@ Nullable T > predicate ) {
429431 Assert .notNull (predicate , "'predicate' must not be null" );
430432 return when (predicate .negate ());
431433 }
@@ -448,7 +450,7 @@ public Member<T> when(Predicate<? super @Nullable T> predicate) {
448450 * @return a {@link Member} which may be configured further
449451 */
450452 @ SuppressWarnings ("unchecked" )
451- public <R > Member <R > as (Extractor <T , ? extends @ Nullable R > extractor ) {
453+ public <R > Member <R > as (Extractor <T , R > extractor ) {
452454 Assert .notNull (extractor , "'adapter' must not be null" );
453455 Member <R > result = (Member <R >) this ;
454456 result .valueExtractor = this .valueExtractor .as (extractor ::extract );
@@ -688,7 +690,7 @@ public String toString() {
688690 * @param <T> the member type
689691 */
690692 @ FunctionalInterface
691- interface ValueExtractor <T > {
693+ interface ValueExtractor <T extends @ Nullable Object > {
692694
693695 /**
694696 * Represents a skipped value.
@@ -722,7 +724,7 @@ default ValueExtractor<T> when(Predicate<? super @Nullable T> predicate) {
722724 * @param extractor the extractor to use
723725 * @return a new {@link ValueExtractor}
724726 */
725- default <R > ValueExtractor <R > as (Extractor <T , ? extends @ Nullable R > extractor ) {
727+ default <R > ValueExtractor <R > as (Extractor <T , R > extractor ) {
726728 return (instance ) -> apply (extract (instance ), extractor );
727729 }
728730
@@ -946,7 +948,7 @@ interface NameProcessor {
946948 * @param existingName the existing and possibly already processed name.
947949 * @return the new name
948950 */
949- String processName (MemberPath path , String existingName );
951+ @ Nullable String processName (MemberPath path , String existingName );
950952
951953 /**
952954 * Factory method to create a new {@link NameProcessor} for the given operation.
@@ -969,15 +971,15 @@ static NameProcessor of(UnaryOperator<String> operation) {
969971 * @param <T> the value type
970972 */
971973 @ FunctionalInterface
972- interface ValueProcessor <T > {
974+ interface ValueProcessor <T extends @ Nullable Object > {
973975
974976 /**
975977 * Process the value at the given path.
976978 * @param path the path of the member containing the value
977979 * @param value the value being written (may be {@code null})
978980 * @return the processed value
979981 */
980- T processValue (MemberPath path , T value );
982+ @ Nullable T processValue (MemberPath path , @ Nullable T value );
981983
982984 /**
983985 * Return a new processor from this one that only applied to members with the
@@ -1018,7 +1020,8 @@ default ValueProcessor<T> whenHasPath(Predicate<MemberPath> predicate) {
10181020 * type.
10191021 */
10201022 default ValueProcessor <T > whenInstanceOf (Class <?> type ) {
1021- return when (type ::isInstance );
1023+ Predicate <@ Nullable T > isInstance = type ::isInstance ;
1024+ return when (isInstance );
10221025 }
10231026
10241027 /**
@@ -1028,7 +1031,7 @@ default ValueProcessor<T> whenInstanceOf(Class<?> type) {
10281031 * @return a new {@link ValueProcessor} that only applies when the predicate
10291032 * matches
10301033 */
1031- default ValueProcessor <T > when (Predicate <T > predicate ) {
1034+ default ValueProcessor <T > when (Predicate <@ Nullable T > predicate ) {
10321035 return (name , value ) -> (predicate .test (value )) ? processValue (name , value ) : value ;
10331036 }
10341037
@@ -1040,7 +1043,7 @@ default ValueProcessor<T> when(Predicate<T> predicate) {
10401043 * @param action the action to apply
10411044 * @return a new {@link ValueProcessor} instance
10421045 */
1043- static <T > ValueProcessor <T > of (Class <? extends T > type , UnaryOperator <T > action ) {
1046+ static <T > ValueProcessor <T > of (Class <? extends T > type , UnaryOperator <@ Nullable T > action ) {
10441047 return of (action ).whenInstanceOf (type );
10451048 }
10461049
@@ -1051,7 +1054,7 @@ static <T> ValueProcessor<T> of(Class<? extends T> type, UnaryOperator<T> action
10511054 * @param action the action to apply
10521055 * @return a new {@link ValueProcessor} instance
10531056 */
1054- static <T > ValueProcessor <T > of (UnaryOperator <T > action ) {
1057+ static <T > ValueProcessor <T > of (UnaryOperator <@ Nullable T > action ) {
10551058 Assert .notNull (action , "'action' must not be null" );
10561059 return (name , value ) -> action .apply (value );
10571060 }
@@ -1065,14 +1068,14 @@ static <T> ValueProcessor<T> of(UnaryOperator<T> action) {
10651068 * @param <R> the result type
10661069 */
10671070 @ FunctionalInterface
1068- interface Extractor <T , R > {
1071+ interface Extractor <T extends @ Nullable Object , R extends @ Nullable Object > {
10691072
10701073 /**
10711074 * Extract from the given value.
10721075 * @param value the source value (never {@code null})
10731076 * @return an extracted value or {@code null}
10741077 */
1075- @ Nullable R extract (T value );
1078+ @ Nullable R extract (@ NonNull T value );
10761079
10771080 }
10781081
0 commit comments