I really did the same because I was having a problem converting ObjectId to JSON.
Then I did something like
@Id private String id; public String getId() { return id(); } public void setId(String id) { this.id = id; }
And everything worked fine until I decided to update the previously inserted document, when I received the Id object, sent it to the page via JSON and received the same updated object also via JSON, and then used the save function from the data store instead of updating the previous data he inserted a new document instead of updating an existing one.
In the worst case, the new document had the same identifier as the previously inserted one, something I was thinking about was impossible.
In any case, I set the private object as ObjectID and just left the get set as a string, and then worked as expected, not sure what helps in your case to think about.
@Id private ObjectId id; public String getId() { return id.toString(); } public void setId(String id) { this.id = new ObjectId(id); }
Destino
source share