org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class models.Job] from JSON String

后端 未结 2 1535
闹比i
闹比i 2021-01-13 04:13

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

2条回答
  •  無奈伤痛
    2021-01-13 05:05

    when limited time +ee: +jax-rs && +persistence, +gson; I have solved it then as:

    @Entity
    @XmlRootElement
    @Table(name="element")
    public class Element implements Serializable {
        public Element(String stringJSON){
            Gson g = new Gson();
            Element a = g.fromJson(stringJSON, this.getClass());
            this.setId(a.getId());
            this.setProperty(a.getProperty());
        }
    
        public Element() {}
        @Id
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        private Integer id;
        ...
    }
    

提交回复
热议问题