I am looking for a way to map _id to id of the doc which I serialize or desrialize from Mongo DB. I am using Jackson for my project. Here is what my id fields looks like.
@Valid
@ObjectId
//not sure what to write here; @JsonProperty(value="_id") gives error
@JsonProperty(value="id")
public String id;
The document which I save in Mongo has entry for both id and _id
{ "_id" : ObjectId("5441902d0364200c32dde326"),
"id" : ObjectId("544178130364350e7bad171b")
}
Is there a way I can map "id" to "_id" for serializing and vice versa when deserializing? The reason I need this mapping is because we have used "id" everywhere (lot of places) on client side.
Related Link: Rename ObjectId _id to id in jackson deserialization with Jongo and MongoDB