Get-method JAX-RS no MessageBodyWriter found for List
<p>When we're accessing a URI, for exemple localhost:8080/QuizProject/webapi/questions, we receive a 500 Internal Server Error.<br>
There is no specific error message and the database receives and gets the information, we know this due to <code>System.out.println</code>. </p>

<p>Two methods for retrieving either all questions or a specific one using an id.</p>

<pre><code>@Path("/questions")
public class QuestionResource {

    private QuestionService questionService = new QuestionService();

@GET
@Produces(MediaType.APPLICATION_JSON)
public List&lt;Question&gt; getAllQuestions()
{
    return questionService.getAllQuestions();
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{questionId}")
public Question getQuestion(@PathParam("questionId") int id)
    {
        return questionService.getQuestion(id);
    }
}
</code></pre>

<p>Class using hibernate-methods</p>

<pre><code>package home.neshoz.Quiz222.services;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import home.neshoz.Quiz222.HibernateTools.HibernateUtil;
import home.neshoz.Quiz222.model.Answer;
import home.neshoz.Quiz222.model.Question;

public class QuestionService
{
    private SessionFactory sessionFactory;
    private Session session;

public List&lt;Question&gt; getAllQuestions()
{
    sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    session.beginTransaction();

    List&lt;Question&gt; questionList = session.createCriteria(Question.class).list();

    session.getTransaction().commit();

    return questionList;

}

public Question getQuestion(int id)
{
    sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    session.beginTransaction();

    Question question = (Question)session.get(Question.class, id);
    Collection&lt;Answer&gt; answerList = question.getAnswerList();
    for(Answer a : answerList)
    {
        System.out.println(a.getAnswer());
    }

    session.getTransaction().commit();
    session.close();

    return question;
}

public Question addQuestion(Question question)
{
    sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    session.beginTransaction();

    session.save(question);
    session.getTransaction().commit();
    session.close();

    return question;
}

public Question editQuestion(int id, String updatedQuestion)
{
    sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    session.beginTransaction();

    Question question = (Question)session.get(Question.class, id);
    question.setQuestion(updatedQuestion);

    session.update(question);
    session.getTransaction().commit();
    session.close();

    return question;
}

public Question deleteQuestion(int id)
{
    sessionFactory = HibernateUtil.getSessionFactory();
    session = sessionFactory.openSession();
    session.beginTransaction();

    Question question = (Question)session.get(Question.class, id);

    session.delete(question);
    session.getTransaction().commit();
    session.close();

    return question;
}
}
</code></pre>

<p>Question Class</p>

<pre><code>package home.neshoz.Quiz222.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@Entity
@Table(name = "Questions")
public class Question implements Serializable
{
    @Id
    @GeneratedValue
    @Column(name = "Id")
    private int id;

    private String question;

    @OneToMany(targetEntity = Answer.class, mappedBy = "question", cascade =   CascadeType.ALL, fetch = FetchType.EAGER)
    private Set&lt;Answer&gt; answerList = new HashSet&lt;Answer&gt;();

    public Question()
    {

    }
    public Question(String question)
    {
        this.question = question;
    }
    public int getId()
    {
        return id;
    }
    public void setId(int id)
    {
        this.id = id;
    }
    public String getQuestion()
    {
        return question;
    }
    public void setQuestion(String question)
    {
        this.question = question;
    }
    public Set&lt;Answer&gt; getAnswerList()
    {
        return answerList;
    }
    public void setAnswerList(Set&lt;Answer&gt; answerList)
    {
        this.answerList = answerList;
    }
}
</code></pre>

<p>Answer-class</p>

<pre><code>package home.neshoz.Quiz222.model;

import java.io.Serializable; 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "Answers")
public class Answer implements Serializable
{
    @Id
    @GeneratedValue
    @Column(name = "Id")
    private int id;

    @Column(name = "Answer")
    private String answer;

    @Column(name = "correctAnswer")
    private String correctAnswer;

    @ManyToOne
    @JoinColumn(name = "Questions_Id")
    private Question question;

    public Answer()
    {

    }
    public Answer(String answer)
    {
        this.answer = answer;
    }

    public Question getQuestion()
    {
        return question;
    }

     public void setQuestion(Question question)
     {
        this.question = question;
    }

    public int getAnswerId()
    {
        return id;
    }
    public void setAnswerId(int answerId)
    {
        this.id = answerId;
    }
    public String getAnswer()
    {
        return answer;
    }
    public void setAnswer(String answer)
    {
        this.answer = answer;
    }
    public String getCorrectAnswer()
    {
        return correctAnswer;
    }
    public void setCorrectAnswer(String correctAnswer)
    {
        this.correctAnswer = correctAnswer;
    }
}
</code></pre>

<p>Main-class.</p>

<pre><code>import org.hibernate.Session;
import org.hibernate.SessionFactory;

import home.neshoz.Quiz222.HibernateTools.HibernateUtil;
import home.neshoz.Quiz222.model.Answer;
import home.neshoz.Quiz222.model.Question;

public class HibernateInsertDemo
{
    private static SessionFactory sessionFactory;
    private static Session session;

    public static void main(String[] args)
    {
        Question q = new Question("F1");

        Answer a1 = new Answer("A1");
        Answer a2 = new Answer("A2");

        q.getAnswerList().add(a1);
        q.getAnswerList().add(a2);

        a1.setQuestion(q);
        a2.setQuestion(q);

        sessionFactory = HibernateUtil.getSessionFactory();
        session = sessionFactory.openSession();
        session.beginTransaction();

        session.save(q);

        session.getTransaction().commit();
        session.close();
    }
}
</code></pre>