Код: Выделить всё
@Document(collection = "mygraph")
public class MyGraph {
@Id
@JsonSerialize(using = ToStringSerializer.class)
public String id;
public Map graph;
public String timestamp;
/**
* Add the default constructor
*/
public MyGraph() {
this.id = new ObjectId().toHexString();
this.graph = new LinkedHashMap();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
this.timestamp = dateFormat.format(new Date());
}
/**
*
* @param instances
*/
public MyGraph(Set instances) {
this.id = new ObjectId().toHexString();
this.graph = new LinkedHashMap();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
this.timestamp = dateFormat.format(new Date());
/* Initialize the graph */
for (Instance instance : instances) {
this.graph.put(instance, new HashSet());
}
}
// get and set method are below
}
< /code>
Однако я получаю следующую ошибку: < /p>
Time elapsed: 0.03 sec
Подробнее здесь: [url]https://stackoverflow.com/questions/40967046/mongodb-cannot-use-a-complex-object-as-a-key-value-java[/url]