ru.integrations.check.utils.ApiUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of CheckingLib Show documentation
Show all versions of CheckingLib Show documentation
This library for help checking response.
The newest version!
package ru.integrations.check.utils;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class ApiUtils {
public static Map extractFilter(Object filters) {
Class> classes = filters.getClass();
List methods = Arrays.asList(classes.getDeclaredFields());
List keys = methods.stream()
.map(Field::getName)
.collect(Collectors.toList());
return getStringObjectMap(filters, classes, keys);
}
public static Map checkValidateFields(Object obj, String... fields) {
Class> classes = obj.getClass();
Field[] methods = classes.getDeclaredFields();
List keys = new ArrayList<>();
for (Field method : methods) {
String name = method.getName();
if (fields != null && fields.length > 0) {
if (!Arrays.asList(fields).contains(name)) {
keys.add(name);
}
} else {
keys.add(name);
}
}
return getStringObjectMap(obj, classes, keys);
}
private static List