Markus Pleines Markus Pleines - 1 year ago 242
JSON Question Can not instantiate value of type [simple type, class models.Job] from JSON String

i use the playframework and tried to deserialize some json into a java object.
It worked fine, exept the relationship in the model. I got the following exception

enter code Can not
instantiate value of type [simple type, class models.Job] from JSON
String; no single-String constructor/factory method (through reference
chain: models.Docfile["job"])

i thought jackson in combination with play could do that:

this is the json


and this my code, nothing special:

public static Result getdata(String dataname) {
ObjectMapper mapper = new ObjectMapper();
try {
Docfile docfile = mapper.readValue((dataname), Docfile.class);

} catch (JsonGenerationException e) {


} catch (JsonMappingException e) {


} catch (IOException e) {



return ok();

Hope there is help for me, thanks


Docfile Bean:

package models;

import java.util.*;

import play.db.jpa.*;
import java.lang.Object.*;
import play.db.ebean.*;
import play.db.ebean.Model.Finder;

import javax.persistence.*;

import com.avaje.ebean.Page;

public class Docfile extends Model {

public Long id;

public String name;

public String description;

public String filepath;

public String contenttype;

public Job job;

public static Finder<Long,Docfile> find = new Model.Finder(
Long.class, Docfile.class

public static List<Docfile> findbyJob(Long job) {
return find.where()
.eq("", job)

public static Docfile create (Docfile docfile, Long jobid) {
docfile.job = Job.find.ref(jobid);;
return docfile;

Answer Source

Either you change your JSON in order to describe your "job" entity :

       "foo", "bar"

or you create a constructor with a String parameter in your Job bean:

public Job(String id) {
// populate your job with its id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download