如何防止春季仇恨返回空链接?

时间:2020-04-10 10:13:22

标签: spring-boot spring-hateoas

我正在生成可以提供链接的响应类。 我想避免在没有提供链接的情况下显示links属性,例如,现在我得到:

{
"links": [], <--not the best
"id": 1,
"category": {
  "links": [],
  "id": 3
}

我想拥有:

{
"id": 1,
"category": {
  "id": 3
},

我尝试定义了全局映射器:

@Configuration
 public class JacksonConfig {

@Autowired
private ObjectMapper objectMapper; //reuse the pre-configured mapper


@PostConstruct
public void setup() {
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY);
}
 }

对于其他所有dto,我都可以使用...除了hateoas链接! 我在做什么错了?

编辑:

我想我又走了一步。仅当RepresentationModel在列表中时才会发生:

@GetMapping("/pet")
public ResponseEntity<List<Pet>> getPets(){ <-- this returns empty links

@GetMapping("/pet")
public ResponseEntity<Pet> getPet(){ <-- this doesn't

0 个答案:

没有答案