我有一个现有的MongoDB,我需要为所有集合编写Java POJO。
有没有可以从mongo集合自动生成POJO的工具?
我能够找到将Mongo集合转换为JSON的工具,但是找不到合适的方法将集合转换为Java POJO。
答案 0 :(得分:0)
使用http://www.jsonschema2pojo.org/
像这样的json
{
"type":"object",
"working":true,
"id":1
}
会产生
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("type")
@Expose
private String type;
@SerializedName("working")
@Expose
private Boolean working;
@SerializedName("id")
@Expose
private Long id;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Boolean getWorking() {
return working;
}
public void setWorking(Boolean working) {
this.working = working;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}