Ali-Alrabi Ali-Alrabi - 1 year ago 89
JSON Question

Convert json String to java object

I have the following jsonString,I need to convert it to java object, I have used the following code to convert it but i get this exception

com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class$Questiongroup]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)

Json String

String jsonStrings ="{"questiongroups":[{"questiongroup":"1000","questions":[{"question":1001,"response":4},{"question":1002,"subquestion":1001,"response":"A2"}]}]}";

public class Responsedetail {

public List<Questiongroup> questiongroups;

public List<Questiongroup> getQuestiongroups() {
return questiongroups;

public void setQuestiongroups(List<Questiongroup> questiongroups) {
this.questiongroups = questiongroups;

public Responsedetail() {

class Questiongroup{

String questiongroup;
List<Question> questions;

public Questiongroup() {

public String getQuestiongroup() {
return questiongroup;

public void setQuestiongroup(String questiongroup) {
this.questiongroup = questiongroup;

public List<Question> getQuestions() {
return questions;

public void setQuestions(List<Question> questions) {
this.questions = questions;
class Question{

String question;
String response;
public Question() {
public String getQuestion() {
return question;
public void setQuestion(String question) {
this.question = question;
public String getResponse() {
return response;
public void setResponse(String response) {
this.response = response;


converting code

String jsonStrings ="{"questiongroups":[{"questiongroup":"1000","questions":[{"question":1001,"response":4},{"question":1002,"subquestion":1001,"response":"A2"}]}]}";

ObjectMapper mapper = new ObjectMapper();

Responsedetail responsedetail = mapper.readValue(response.getDetails(), Responsedetail.class);


Answer Source

Your Questiongroup class is nested inside the Responsedetail class, and Question is nested inside Questiongroup.

Since you didn't make them static, they are inner classes.

Add static to the nested classes to make them static nested classes.

Alternatively, make them all top-level classes in their own .java source files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download