Creating Java POJOs from Mongo collections

1.1k views Asked by At

I have a existing MongoDB and I need to write Java POJOs for all the collections.

Is there any tool which can auto-generate the POJOs from the mongo collections?

I am able to find tools to convert Mongo collections to JSON, but could not find a suitable way to convert the collections to Java POJOs.

1

There are 1 answers

2
ΦXocę 웃 Пepeúpa ツ On

using the http://www.jsonschema2pojo.org/

a json like:

{
  "type":"object",
  "working":true,
  "id":1
}

will produce

-----------------------------------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;
}

}