CrudRepository REST响应中的重复_links键

时间:2015-10-20 15:24:29

标签: spring-data-rest

问题: CrudRepository使用重复的_links键返回错误的JSON响应

{"_links" : { },  
 "_embedded" : {
    "skills" : [ {
      "name" : "REST",
      "_links" : { }, <----------- Empty Links
      "_embedded" : { },
      "_links" : { <-------------- Usefull Links
        "self" : {
          "href" : "http://localhost:8081/api/skills/1",
          "templated" : false
        }
      }
    } ]   } }

使用过的类: 库:     import org.springframework.data.repository.CrudRepository;

public interface SkillRepository extends CrudRepository<Skill, Long> {}

实体:

@Entity
@Getter
@Setter
public class Skill {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String name;

}

如果我包含jackson-databind,则会出现问题。

        <artifactId>jackson-databind</artifactId>
        <version>2.6.0</version> 

1 个答案:

答案 0 :(得分:2)

最新版本的spring-hateoas包括jackson-databind 2.4.6。

在jackson-databind 2.6.0中JsonSerialize.Inclusion被弃用;应该使用JsonInclude代替。来自spring-hateoas(ResourcesMixinResourceSupportMixin&amp; LinkMixin)的Mixin类使用显然被忽略的JsonSerialize.Inclusion

解决方案:使用jackson-databind 2.5.4(或更低版本),直到jackson版本在spring-hateoas中更新。

相关问题