#1515 - Fix key rendering of embedded resources.
We now also eagerly map the keys for the _embedded map in a HAL response to Strings to make sure they work properly when sorting of map keys is activated for the Jackson ObjectMapper.
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -333,7 +334,11 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
}
|
||||
}
|
||||
|
||||
provider.findValueSerializer(Map.class, property).serialize(embeddeds, jgen, provider);
|
||||
Map<String, Object> map = new LinkedHashMap<>(embeddeds.size());
|
||||
embeddeds.forEach((key, it) -> map.put(key.value(), it));
|
||||
|
||||
provider.findValueSerializer(Map.class, property) //
|
||||
.serialize(map, jgen, provider);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -644,6 +644,15 @@ class Jackson2HalIntegrationTest {
|
||||
.writeValueAsString(new RepresentationModel<>().add(Link.of("/href")));
|
||||
}
|
||||
|
||||
@Test // #1515
|
||||
void rendersEmbeddedKeysWhenMapEntrySortingIsEnabled() throws Exception {
|
||||
|
||||
List<SimplePojo> embbededs = Arrays.asList(new SimplePojo(), new SimpleAnnotatedPojo());
|
||||
|
||||
mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
|
||||
.writeValueAsString(CollectionModel.of(embbededs));
|
||||
}
|
||||
|
||||
@Test // #1516
|
||||
void considersNamingBase() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user