Skip to content

Instantly share code, notes, and snippets.

@jnizet
Last active April 28, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnizet/ab9fce8b8593cf4055550c7a38eceac6 to your computer and use it in GitHub Desktop.
Save jnizet/ab9fce8b8593cf4055550c7a38eceac6 to your computer and use it in GitHub Desktop.
package com.foo;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
public class QnA implements Serializable {
private long idQnA;
private String question;
private List<String> responses;
public QnA() {
}
public QnA(String question, List<String> responses) {
this.question = question;
this.responses = responses;
}
public long getIdQnA() {
return idQnA;
}
public void setIdQnA(long idQnA) {
this.idQnA = idQnA;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public List<String> getResponses() {
return responses;
}
public void setResponses(List<String> responses) {
this.responses = responses;
}
public static void main(String[] args) throws IOException {
ObjectMapper om = new ObjectMapper();
String json = "{ \"idQnA\": 205,\n" +
" \"question\": \"test\",\n" +
" \"responses\": [\"test\",\"test\"]}";
om.readValue(json, QnA.class); // this works fine
String json2 = "{ \"idQnA\": 205,\n" +
" \"question\": \"test\",\n" +
" \"responses\": [{}, {}}";
om.readValue(json2, QnA.class); // this works fine
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment