com.monitorjbl.json.Match Maven / Gradle / Ivy
package com.monitorjbl.json;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
public class Match {
private final Set includes = new HashSet<>();
private final Set excludes = new HashSet<>();
private final Map> transforms = new HashMap<>();
Match() {
}
/**
* Mark fields for inclusion during serialization.
*
* @param fields The fields to include
* @return Match
*/
public Match include(String... fields) {
if(fields != null) {
includes.addAll(Arrays.asList(fields));
}
return this;
}
/**
* Mark fields for exclusion during serialization.
*
* @param fields The fields to exclude
* @return Match
*/
public Match exclude(String... fields) {
if(fields != null) {
excludes.addAll(Arrays.asList(fields));
}
return this;
}
/**
* Mark a field for transformation during serialization.
*
* @param field The fields to include
* @param transformer The function to transform the field. Will be provided with the whole object and the field.
* @param The object being serialized
* @param The field being serialized
* @param The value of the field to serialize
* @return Match
*/
@SuppressWarnings("unchecked")
public Match transform(String field, BiFunction transformer) {
transforms.put(field, (BiFunction