Daily Archives: June 10, 2021

java – Spring Mergeable

There are 4 type of Mergeable Object in Spring

ManagedList
ManagedProperties
ManagedMap
ManagedSet

Take ManagedList as example

if mergeEnabled is set to be false, merge will stop
if parent is null, return itself.
and finally it will add parent firstly and then add children.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	@Override
	@SuppressWarnings("unchecked")
	public List<E> merge(@Nullable Object parent)
	{
		if (!this.mergeEnabled) {
			throw new IllegalStateException("Not allowed to merge when the 'mergeEnabled' property is set to 'false'");
		}
		if (parent == null) {
			return this;
		}
		if (!(parent instanceof List)) {
			throw new IllegalArgumentException("Cannot merge with object of type [" + parent.getClass() + "]");
		}
		List<E> merged = new ManagedList<>();
		merged.addAll((List<E>) parent);
		merged.addAll(this);
		return merged;
	}