1

Let's say we have a simple document type defined in mongodb:

{
  _id : OjbectId(xxx),
  value : A
}

But the value A here could be float, integer, boolean or string. How can I map it into a java entity?

Here's a template which only mapped _id:

@Document(collection = "my_document")
public class MyDocument {
  @Id
  private String id;

  public String getId() {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }
}

Thanks.

1
  • OK. Good. Suddenly I understand Object. Commented Apr 29, 2016 at 9:52

1 Answer 1

1

As @titogeo said in a comment, you could use Object like a generic type as it's the super type of all types.

You can read more about data mapping conversion in Spring Data MongoDB - Reference Documentation - Mapping.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.