小编V. *_*kyi的帖子

使用spring-hateoas反序列化JSON(链接+嵌入式容器)的便捷方法是什么?

同事!

我们希望将Rest Client写入遵循HATEOAS原则的服务.所以我们有以下HAL + JSON表示,我们想使用spring-hateoas反序列化它:

{
    "id": "1",
    "title": "album title",
    "artistId": "1",
    "stockLevel": 2,
    "_links": {
        "self": {"href": "http://localhost:8080/rest/albums/1"},
        "artist": {"href": "http://localhost:8080/rest/artist/1"}
    },
    "_embedded": {
        "albums": [{ //can be array or object
            "id": "1",
            "title": "album title",
            "artistId": "1",
            "stockLevel": 2,
            "_links": {
                "self": {"href": "http://localhost:8080/rest/albums/1"}
            }
        }],
        "artist": { //can be array or object
            "id": "1",
            "name": "artist name",
            "_links": {
                "self": {"href": "http://localhost:8080/rest/artist/1"}
            }
        } //.... 
    }
}
Run Code Online (Sandbox Code Playgroud)

我们期望这样的java对象:

HalResource {
    Resource<Album> //entity 
    List<Link> // _links
    List<Resource<BaseEntity>>{ …
Run Code Online (Sandbox Code Playgroud)

json hateoas jackson spring-hateoas json-deserialization

6
推荐指数
0
解决办法
1819
查看次数