DATAREST-864 - NestedEntitySerializer now handles Maps correctly.

Previously, NestedEntitySerializer failed to handle Maps correctly as the logic to convert the found values to nested resources tried to handle the values as is, not explicitly looking at the values instead.

We now use an explicit code path to turn the values into resources so that links pointing to other resources are rendered correctly.

Original pull request: #219.
This commit is contained in:
Oliver Gierke
2016-09-15 16:33:59 +02:00
parent 1c70b9175d
commit 254c4515e1
3 changed files with 45 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -351,6 +353,17 @@ public class PersistentEntityJackson2Module extends SimpleModule {
provider.defaultSerializeValue(resources, gen);
} else if (value instanceof Map) {
Map<?, ?> source = (Map<?, ?>) value;
Map<Object, Object> resources = CollectionFactory.createMap(value.getClass(), source.size());
for (Entry<?, ?> entry : source.entrySet()) {
resources.put(entry.getKey(), toResource(entry.getValue()));
}
provider.defaultSerializeValue(resources, gen);
} else {
provider.defaultSerializeValue(toResource(value), gen);
}