#1157 - Fixed custom EntityModel serialization for Map payloads.

Using a custom serializer seems to break downstream projects that also register serializers for EntityModel. We're now using extra methods on EntityModel itself that do the trick as well.
This commit is contained in:
Oliver Drotbohm
2019-12-12 10:03:21 +01:00
parent 5502bfdf85
commit ebe7038a48
2 changed files with 7 additions and 74 deletions

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
@@ -80,6 +81,11 @@ public class EntityModel<T> extends RepresentationModel<EntityModel<T>> {
// Hacks to allow deserialization into an EntityModel<Map<String, Object>>
@JsonAnyGetter
private Map<String, Object> getMapContent() {
return Map.class.isInstance(content) ? (Map<String, Object>) content : null;
}
@JsonAnySetter
private void setPropertiesAsMap(String key, Object value) {
getOrInitAsMap().put(key, value);