new Gson().toJson(new ObjectId())
When I do the above, the output I get is
"_id" : { "_time" : 1374347520 , "_machine" : -1025067326 , "_inc" : 585905201 , "_new" : false}
But Actually I want it to be as
"_id":{"$oid":51eae100c2e6b6c222ec3431}
which is the usual mongodb ID format. What is the preferable method in Java for this?
Update:
My value object
import com.google.gson.annotations.SerializedName;
import org.bson.types.ObjectId;
public class TaskObject {
@SerializedName("_id")
private ObjectId _id;
@SerializedName("revNo")
private int revNo;
}
I am trying to store this to mongodb with a custom _id
TaskObject taskObject = new TaskObject();
taskObject.set