我有两个模型:
1-资源假期:
@Id
private String resourceID;
private List<Vacation> vacationList;
2-假期:
@Id
private String id;
private String start;
private String title;
我插入 ResourceVacation 后的 JSON:
{“_id”:“foo”,“_class”:“com.test.model.ResourceVacation”,“vacationList”:[{“_id”:“1”,“start”:“abc”,“title”:“测试” } ] }
我需要更新假期;如果我需要的资源 ID 已经存在于 ResourceVacation 中,请将“vacationList”替换为我拥有的 json。
ELSE:插入一个新的 ResourceVacation
Vacation vacation = new Vacation("a", "a", "a");
List<Vacation> list = new ArrayList<Vacation>();
list.add(vacation);
ResourceVacation resourceVacation = new ResourceVacation("foo", list);
MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate();
DBCollection db = mongoOperations.getCollection("resourceVacation");
BasicDBObject myQuery = new BasicDBObject("_id", resourceVacation.getResourceID());
BasicDBObject myUpdate = new BasicDBObject("push ", new BasicDBObject("vacationList",
resourceVacation.getVacationList()));
db.update(myQuery, myUpdate);
我得到以下异常:
java.lang.IllegalArgumentException: can't serialize class com.springway.model.Vacation