Cannot use a complex object as a key value

I am trying to save an object in Mongodb which has one property of type Map. The key for the map is my own class (something similar to say Employee having certain attributes). The issue is that when I try to save the object , I am getting an error
“ Cannot use a complex object as a key value.”

I read multiple details and it may be more of a Spring issue rather than Mongodb but wanted to post this question here just in case there is some solution already?

It is more of a spring issue,
the keys type must be a MongoSimpleTypes
It’s because the keys of a util.Map are mapped to String values.

check this link: