I am doing POJO serialization / deserialization using Jackson. Here is a POJO exemple :
public class Pojo {
public String productId;
public String name;
}
I have to read the field productId
in this JSON :
{"productId":"1","name":"exemple"}
But also in :
{"_id":"1","name":"exemple"}
To make it short, I would like to use the same object to read the field in a JSON file found somewhere and to save the object as this in MongoDB, using productId
as the primary key, which has to be named _id
.
Since I am using Jackson (fasterxml) both to read from the file and to write to the database, I can not find a way to do so, except by creating a new class with the same fields (or inheritance) and fill them one by one. Basically, I would like to find a way to put 2 @JsonProperty annotations on productId
.