Skip to content

Map content is not getting serialized properly #1352

@uber-cool

Description

@uber-cool

spring-hateoas version: 1.2.0-SNAPSHOT
When the content is a Map in EntityModel, it is not getting converted in proper JSON. The content is getting duplicated.

Test case to describe this behavior:

        @Test
	public void testSerializationOfMap() throws JsonProcessingException {
		final Map map = new HashMap();
		map.put("key", "value");
		final String serialized = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(EntityModel.of(map));

		System.out.println("Incorrect representation, key value are duplicating at root level as well as under content");
		System.out.println(serialized);

		class KeyValue {
			public KeyValue(String value) {
				key = value;
			}
			public String key;
		}

		KeyValue keyValue = new KeyValue("value");
		final String serializedKeyValue = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(EntityModel.of(keyValue));
		System.out.println("Correct representation when using custom class KeyValue");
		System.out.println(serializedKeyValue);
	}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions