JSON returns only the last entry of a Hashmap property via Spring Boot Rest Controller

31 views Asked by At

I have a Map<Object, List> property. It correctly persists to SQL and a Spring Boot Repository correctly returns the Map. However, the JSON response from a Spring Boot Rest Controller only transports the LAST key-value entry in this Map and not all of its entries.

Is this a limitation of Spring Boot Controllers returning JSON or could I have overlooked something simple. I understand there are JSON libraries out there and so trying to clarify if this is required or if it's likely I've overlooked something. I've seen lots of close questions but none which quite match my circumstances so not sure.

EDIT: some additional troubleshooting reveals that this single return is due to the Map's Object Key having its own Nested Object property and an ENUM property. These are the same and so the Key is seen as a duplicate even though there are other Object Key properties which make the key unique so any insight on this is still helpful.

Thanks so much.

I'm expecting the JSON response to list out all entries of the Map<Object, List> property.

1

There are 1 answers

1
abdlost On

Just to close this off. The Objects being used as Hashmap Keys shared a hashcode collision. Fixed with a hashCode()/equals() Override on the Entity.