无法将类javax.persistence.Entity(类型注释)反序列化为

时间:2018-12-20 08:46:47

标签: java spring hibernate spring-mvc spring-boot

我有一个叫做Entity的类,它是javax.persistance.Entity的类型,

向Spring rest控制器发出请求。我遇到错误了

  

2018-12-20 14:10:3​​5.829警告22332 --- [nio-8080-exec-3]   .c.j.MappingJackson2HttpMessageConverter:无法评估Jackson   类型[[简单类型,类com.model.Application]]的反序列化:   com.fasterxml.jackson.databind.JsonMappingException:无法   将类javax.persistence.Entity(类型注释)反序列化为   Bean 2018-12-20 14:10:3​​5.832 WARN 22332 --- [nio-8080-exec-3]   .c.j.MappingJackson2HttpMessageConverter:无法评估Jackson   类型[[简单类型,类com.model.Application]]的反序列化:   com.fasterxml.jackson.databind.JsonMappingException:无法   将类javax.persistence.Entity(类型注释)反序列化为   Bean 2018-12-20 14:10:3​​5.837调试22332--[nio-8080-exec-3]   .w.s.m.m.a.ServletInvocableHandlerMethod:无法解析参数   类型为“ com.model.Application”的0。

     

org.springframework.web.HttpMediaTypeNotSupportedException:内容   类型'application / json; charset = UTF-8'在以下位置不受支持   org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:226)   〜[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)   〜[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)   〜[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)   〜[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)   [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)   [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)   [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)   [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)   [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "applications")
public class Application implements Serializable {

    protected Long   id;
    protected String name;
    protected String createdBy;
    protected Long   createdTime;
    protected String modifiedBy;
    protected Long   modifiedTime;


    public Application() {

    }
    public Application(Long id, String name, String createdBy, Long createdTime, String modifiedBy, Long modifiedTime) {

        this.id = id;
        this.name = name;
        this.createdBy = createdBy;
        this.createdTime = createdTime;
        this.modifiedBy = modifiedBy;
        this.modifiedTime = modifiedTime;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", columnDefinition = "int(11)")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "name", length = 128)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "createdBy", columnDefinition = "VARCHAR(128)", nullable = false)
    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Column(name = "createdTime", columnDefinition = "DATETIME default CURRENT_TIMESTAMP")
    public Long getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }

    @Column(name = "modifiedBy", columnDefinition = "VARCHAR(128)")
    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Column(name = "modifiedTime", columnDefinition = "DATETIME default CURRENT_TIMESTAMP")
    public Long getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Long modifiedTime) {
        this.modifiedTime = modifiedTime;
    }



}










import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.sql.Date;
import java.util.Objects;

// TODO: Enable for JPA and modify as needed to save linked entities. Modify as needed
@javax.persistence.Entity
@Table(name = "entities")
public class Entity implements Serializable {

    protected Long id;
    protected String name;
    protected int active;
    protected String fields;
    protected String createdBy;
    protected Date createdTime;
    protected String modifiedBy;
    protected Date modifiedTime;
    protected Long appId;


    public DiabloEntity() {

    }

    public DiabloEntity(Long id, String name, String fields, String createdBy, Date createdTime, String modifiedBy, Date modifiedTime) {
        this.id = id;
        this.name = name;

        this.fields = fields;
        this.createdBy = createdBy;
        this.createdTime = createdTime;
        this.modifiedBy = modifiedBy;
        this.modifiedTime = modifiedTime;
    }

    @Column(name = "name", columnDefinition = "VARCHAR(128)", nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", columnDefinition = "INT(11)")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "appId", columnDefinition = "INT(11)")
    public Long getAppId() {
        return appId;
    }

    public void setAppId(Long appId) {
        this.appId = appId;//application.getId();
    }


    @Column(name = "fields", columnDefinition = "JSON")
    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
    }

    @Column(name = "createdBy", columnDefinition = "VARCHAR(128)", nullable = false)
    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Column(name = "createdTime", columnDefinition = "INT(11)")
    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    @Column(name = "modifiedBy", columnDefinition = "VARCHAR(128)")
    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Column(name = "modifiedTime", columnDefinition = "INT(11)")
    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    @Column(name = "active", columnDefinition = "INT(1)")
    public int getActive() {
        return active;
    }

    public void setActive(int active) {
        this.active = active;
    }


}

0 个答案:

没有答案