*
* @param value can be {@literal null}.
*/
public void add(Object source) {
EmbeddedWrapper wrapper = wrappers.wrap(source);
if (wrapper == null) {
return;
}
String collectionRel = getDefaultedRelFor(wrapper, true);
String collectionOrItemRel = collectionRel;
if (!embeddeds.containsKey(collectionRel)) {
collectionOrItemRel = getDefaultedRelFor(wrapper, wrapper.isCollectionValue());
}
Object currentValue = embeddeds.get(collectionOrItemRel);
Object value = wrapper.getValue();
if (currentValue == null && !wrapper.isCollectionValue()) {
embeddeds.put(collectionOrItemRel, value);
return;
}
List<Object> list = new ArrayList<Object>();
list.addAll(asCollection(currentValue));
list.addAll(asCollection(wrapper.getValue()));
embeddeds.remove(collectionOrItemRel);
embeddeds.put(collectionRel, list);
}