I am currently working on an java application that stores Objects in a mongoDB using mongojack. Everything worked fine until I started to implement some helper methods in the Object to return directly nested Objects instead of the DBRef.
public class Dish {
private String id =null;
private String name;
private DBRef<User,String> author;
@JsonCreator
public Dish(@ObjectId @JsonProperty("_id") String id,
@JsonProperty("name") String name,
@JsonProperty("author") DBRef<User, String> author)){
this.id = id;
this.name = name;
this.author = author;}
@ObjectId
@Id
public String getId() {
return id;
}
@JsonProperty
public String getName() {
return name;
}
@JsonProperty
public DBRef<User, String> getAuthor() {
return author;
}
@JsonIgnore
public User getAuthorExtracted() {
return author.fetch();
}
However adding that last method results in adding authorExtracted to the saved JSON in mongoDB. Is there anyway to put some helper methods like this in the actual dish, without messing up saving the Object to the database?