0

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?

LST
  • 345
  • 4
  • 13
  • Just quickly. Surely there is an anotation to "not serialize" or something similar. It's a commonplace approach with other libraries/frameworks. – Blakes Seven Jun 25 '15 at 14:58
  • I tried @JsonIgnore what is usually suggested. But that does not seem to do the trick for my case. – LST Jun 26 '15 at 14:18

0 Answers0