com.envimate.mapmate.serialization.CircularReferenceDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapmate Show documentation
Show all versions of mapmate Show documentation
MapMate is a modern mapping framework in the scope of mapping data in
Json, XML, or YAML format into DTOs composed and vice versa.
/*
* Copyright (C) 2017 [Richard Hauswald, Nune Isabekyan] (envimate GmbH - https://envimate.com/)
*/
package com.envimate.mapmate.serialization;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* CircularReferenceDetector provides ways to scan and detect circular references in a given object.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public final class CircularReferenceDetector {
private static final int WRAPPER_COUNT = 10;
private static final Set> WRAPPER_TYPES = getWrapperTypes();
/**
* Detect scans a given object for circular references in its publicly accessible fields recursively.
*
* @param subject to be scanned
* @throws CircularReferenceException if a circular reference is found.
*/
void detect(final Object subject) {
if (Objects.isNull(subject)) {
return;
}
detect(subject, new ArrayList<>());
}
private void detect(final Object subject, final ArrayList