Reputation: 2538
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.
Upvotes: 1
Views: 4097
Reputation: 11016
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.
Upvotes: 1