我尝试将下面的文档插入到mongo集合中,但是我收到一个名为
的错误线程中的异常" main" org.bson.codecs.configuration.CodecConfigurationException:无法找到com.google.gson.JsonObject类的编解码器
docObj的价值
Document{{files=[Document{{filename=newfile2018-04-25_03-32-01, filedata=[], unalloccount=0}}], employeelist=[{"employeeid":"employee0","datacount":1}], status=new, seq=0, _id=jobs0}}
jobDetails的值为
{"jobname":"dfd","filelist":["newfile2018-04-25_03-32-01"],"employeelist":[{"employeeid":"employee0","datacount":1}]}
我的Java代码如下所示:
public String createJob(String appCode, JsonObject jobDetails) {
Document job = new Document();
Document fileObj = new Document();
List<Document> fileDataList = null;
List<Document> fileList = new ArrayList<Document>();
System.out.println(jobDetails);
for (JsonElement file : (JsonArray) jobDetails.get("filelist")) {
fileObj = new Document();
fileDataList = copyFileDataToJob(appCode, file.getAsString());
fileObj.put("filename", file.getAsString());
fileObj.put("filedata", fileDataList);
fileObj.put("unalloccount", fileDataList.size());
fileList.add(fileObj);
}
job.put("files", fileList);
job.put("employeelist",jobDetails.get("employeelist"));
job.put("status", "new");
insertObject(appCode, "jobs", job, null);
return null;
}
public String insertObject(String appCode, String collName, Document docObj, Map<String, Object> specificParams) {
JsonObject returnObj = new JsonObject();
MongoClient cli = ProfManDBFactory.getMongoClient();
MongoDatabase db = cli.getDatabase(appCode);
MongoCollection<Document> table = db.getCollection(collName);
int nextSeq = getNextSequence(db, collName);
docObj.put("seq", nextSeq);
docObj.put("_id", collName + nextSeq);
System.out.println(docObj);
System.out.println(docObj.getClass().getName());
if (specificParams != null) {
docObj.putAll(specificParams);
}
>//ERROR OCCURS IN THIS LINE.
table.insertOne(docObj);
returnObj.addProperty(RS_STATUS, MSG_SUCCESS);
returnObj.addProperty(RS_APPCODE, appCode);
return returnObj.toString();
}