0

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.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614

1 Answers1

0

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

}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • Thank you for your responses. Well, I am already using MongoToJSON and JSONToPOJO. In this , I need to do lot of changes and its taking lot of time. Example : When I export Mongo collections to JSON, I need to find one document which is having no null value and then I put that in the plugin: JSONToPOJO. I was hoping to find a tool like JPA tool in eclipse which generates all entities at once intelligently. – Vishal Awasthi Nov 29 '19 at 16:53
  • If nothing comes up it would be a cool thing to write this, @VishalAwasthi. If the structures aren't complicated its. – Curiosa Globunznik Nov 30 '19 at 09:00