ValueProcessor Type — spring-boot Architecture
Architecture documentation for the ValueProcessor type/interface in JsonWriter.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/main/java/org/springframework/boot/json/JsonWriter.java lines 973–1062
@FunctionalInterface
interface ValueProcessor<T extends @Nullable Object> {
/**
* Process the value at the given path.
* @param path the path of the member containing the value
* @param value the value being written (may be {@code null})
* @return the processed value
*/
@Nullable T processValue(MemberPath path, @Nullable T value);
/**
* Return a new processor from this one that only applied to members with the
* given path (ignoring escape characters).
* @param path the patch to match
* @return a new {@link ValueProcessor} that only applies when the path matches
*/
default ValueProcessor<T> whenHasUnescapedPath(String path) {
return whenHasPath((candidate) -> candidate.toString(false).equals(path));
}
/**
* Return a new processor from this one that only applied to members with the
* given path.
* @param path the patch to match
* @return a new {@link ValueProcessor} that only applies when the path matches
*/
default ValueProcessor<T> whenHasPath(String path) {
return whenHasPath(MemberPath.of(path)::equals);
}
/**
* Return a new processor from this one that only applied to members that match
* the given path predicate.
* @param predicate the predicate that must match
* @return a new {@link ValueProcessor} that only applies when the predicate
* matches
*/
default ValueProcessor<T> whenHasPath(Predicate<MemberPath> predicate) {
return (path, value) -> (predicate.test(path)) ? processValue(path, value) : value;
}
/**
* Return a new processor from this one that only applies to member with values of
* the given type.
* @param type the type that must match
* @return a new {@link ValueProcessor} that only applies when value is the given
* type.
*/
default ValueProcessor<T> whenInstanceOf(Class<?> type) {
Predicate<@Nullable T> isInstance = type::isInstance;
return when(isInstance);
}
/**
* Return a new processor from this one that only applies to member with values
* that match the given predicate.
* @param predicate the predicate that must match
* @return a new {@link ValueProcessor} that only applies when the predicate
* matches
*/
default ValueProcessor<T> when(Predicate<@Nullable T> predicate) {
return (name, value) -> (predicate.test(value)) ? processValue(name, value) : value;
}
/**
* Factory method to crate a new {@link ValueProcessor} that applies the given
* action.
* @param <T> the value type
* @param type the value type
* @param action the action to apply
* @return a new {@link ValueProcessor} instance
*/
static <T> ValueProcessor<T> of(Class<? extends T> type, UnaryOperator<@Nullable T> action) {
return of(action).whenInstanceOf(type);
}
/**
* Factory method to crate a new {@link ValueProcessor} that applies the given
* action.
* @param <T> the value type
* @param action the action to apply
* @return a new {@link ValueProcessor} instance
*/
static <T> ValueProcessor<T> of(UnaryOperator<@Nullable T> action) {
Assert.notNull(action, "'action' must not be null");
return (name, value) -> action.apply(value);
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free