未找到使用Json的类的序列化程序

未找到使用Json的类的序列化程序,json,rest,spring-boot,jackson,jackson-databind,Json,Rest,Spring Boot,Jackson,Jackson Databind,我有一个基本的SpringBoot 2.1.2.RELEASE应用程序。使用Spring初始值设定项、JPA、嵌入式Tomcat、Thymeleaf模板引擎,并将其打包为具有restful体系结构的可执行JAR 我有一个在RestMethod中返回的对象: public class MenuAlarm { /** * */ public MenuAlarm() { super(); } /** *

我有一个基本的SpringBoot 2.1.2.RELEASE应用程序。使用Spring初始值设定项、JPA、嵌入式Tomcat、Thymeleaf模板引擎,并将其打包为具有restful体系结构的可执行JAR

我有一个在RestMethod中返回的对象:

public class MenuAlarm {



    /**
     * 
     */
    public MenuAlarm() {
        super();
    }


    /**
     * 
     */
    public MenuAlarm(Menu menu) {

        this.menuAlias = menu.getName();
        this.menuId = menu.getId();

        menu
            .getAlerts()
            .forEach(a -> alarms.add(new Alarm(a)));

    }

    class Alarm {

        public Alarm(MenuAlert menuAlert) {

            this.percentage = menuAlert.getPercentage();

            if (menuAlert.getCriteria() > 1) {
                this.increase = true;
            } else {
                this.increase = false;
            }
            this.enabled = menuAlert.isEnabled();
        }

        public Alarm() {
            super();
        }

        Integer percentage;

        boolean increase;

        boolean enabled;

    }

    String menuAlias;

    Long menuId;

    List<Alarm> alarms = new ArrayList<Alarm>();

    public String getMenuAlias() {
        return menuAlias;
    }

    public void setMenuAlias(String menuAlias) {
        this.menuAlias = menuAlias;
    }

    public Long getMenuId() {
        return MenuId;
    }

    public void setMenuId(Long menuId) {
        this.menuId = menuId;
    }

    public List<Alarm> getAlarms() {
        return alarms;
    }

    public void setAlarms(List<Alarm> alarms) {
        this.alarms = alarms;
    }
}

您还没有告诉Jackson如何序列化内部报警类

Jackson将尝试将其序列化为bean(从而引用BeanSerializer),但您还没有在Alarm上提供任何与JavaBeans兼容的getter方法


您可以选择为Alarm编写自定义序列化程序,或添加一些公共getter方法,如getPercentage。

在entity类中使用此注释。这是错误的根源

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})