@JsonIgnore在Spring Boot应用程序上不起作用

时间:2019-04-01 15:02:38

标签: java json rest spring-boot

我正在创建一个RESTful Web服务。一切正常,除非我在其中一个具有com.google.auto.value.AutoValue关系的类中添加sticky注释。我得到了:

  

com.fasterxml.jackson.databind.exc.InvalidDefinitionException:未找到类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器,也未发现创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过参考链:java.util.ArrayList [0]-> com.packt.cardatabase.domain.Car [“所有者”]-> com.packt.cardatabase.domain.Owner $ HibernateProxy $ AcLDWRSD [“ hibernateLazyInitializer”])

我的pom.xml:


html,
body {
  height: 100%
}

/* This piece of code will do the magic */
.header-menu {
  position: sticky;
  position: -webkit-sticky;
  top: 0;
}

.navbar-nav {
  margin: 0 auto;
}

.navbar {
  z-index: 1000;
  background-color: #191919 !important;
}

.stickyLandingDiv {
  padding-top: 55px;
}

#landingDiv {
  height: 100%;
}

#landingPageImage {
  background-image: url(/Assets/Images/background6-min.png);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  height: 100%;
}

我的控制器:

@JsonIgnore

我的实体:

@OneToMany

删除<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.5.0</version> </dependency> </dependencies> 后,可以从数据库中获取序列化数据。但是添加注释时,不是@RestController public class CarController { @Autowired private CarRepository repository; @RequestMapping("/cars") public Iterable<Car> getCars(){ return repository.findAll(); } } 格式。

1 个答案:

答案 0 :(得分:0)

在您的Car类中,将此添加到“所有者”声明上方:

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