Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Traverson的基于HAL的REST服务客户端_Java_Rest_Client_Spring Hateoas - Fatal编程技术网

Java 使用Traverson的基于HAL的REST服务客户端

Java 使用Traverson的基于HAL的REST服务客户端,java,rest,client,spring-hateoas,Java,Rest,Client,Spring Hateoas,我正试图编写一个Java程序来使用我利用spring.io上的教程编写的基于REST的web服务的输出。当我运行SpringBoot bootRun时,JSON输出很好地构建了嵌入式数据和链接,如下所示: { "_embedded": { "invoiceList": [ { "id": 4, "seqNum": 1, "fileId": null, "fileName":

我正试图编写一个Java程序来使用我利用spring.io上的教程编写的基于REST的web服务的输出。当我运行SpringBoot bootRun时,JSON输出很好地构建了嵌入式数据和链接,如下所示:

 {
"_embedded": {
    "invoiceList": [
        {
            "id": 4,
            "seqNum": 1,
            "fileId": null,
            "fileName": null,
            "invoiceNumber": "10080",
            "invoiceDate": "2018-06-18T05:00:00.000+0000",
            "invoiceTotal": 1000,
            "sourceLastModified": "2018-11-30T16:22:23.000+0000",
            "lastModified": "2018-11-30T16:22:23.000+0000",
            "validFrom": "2018-11-30T16:22:23.000+0000",
            "validTo": "9999-12-31T06:00:00.000+0000",
            "_links": {
                "self": {
                    "href": "http://localhost:8086/vadir/dental/invoices/4"
                },
                "invoices": {
                    "href": "http://localhost:8086/vadir/dental/invoices"
                },
                "claims": {
                    "href": "http://localhost:8086/vadir/dental/claims?invoice=10080"
                }
            }
        },
        {
            "id": 5,
            "seqNum": 1,
            "fileId": null,
            "fileName": null,
            "invoiceNumber": "10080",
            "invoiceDate": "2018-06-18T05:00:00.000+0000",
            "invoiceTotal": 500,
            "sourceLastModified": "2018-11-30T16:22:23.000+0000",
            "lastModified": "2018-11-30T16:22:23.000+0000",
            "validFrom": "2018-11-30T16:22:23.000+0000",
            "validTo": "9999-12-31T06:00:00.000+0000",
            "_links": {
                "self": {
                    "href": "http://localhost:8086/vadir/dental/invoices/5"
                },
                "invoices": {
                    "href": "http://localhost:8086/vadir/dental/invoices"
                },
                "claims": {
                    "href": "http://localhost:8086/vadir/dental/claims?invoice=10080"
                }
            }
        }
    ]
},
"_links": {
    "self": {
        "href": "http://localhost:8086/vadir/dental/invoices/last"
    }
}
}

我已经找到了关于Traverson和SO问题的文档。然而,当我使用

ParameterizedTypeReference<Resources<Resource<DentalInvoice>>> parameterizedTypeReference =
        new ParameterizedTypeReference<Resources<Resource<DentalInvoice>>> () {
        };
    Traverson traverson =
        new Traverson (new URI ("http://localhost:8086/vadir/dental/invoices/last"), MediaTypes.HAL_JSON);
    Resources<Resource<DentalInvoice>> invoiceResources = traverson
                                                    //.follow ((String) null)
                                                    .follow ("$._embedded.invoiceList")
                                                    .toObject (parameterizedTypeReference);
ParameteredTypeReference ParameteredTypeReference=
新的ParameteredTypeReference(){
};
横穿=
新的遍历(新的URI(“http://localhost:8086/vadir/dental/invoices/last),MediaTypes.HAL_JSON);
Resources invoiceResources=traverson
//.follow((字符串)null)
.follow(“$.\u嵌入式发票列表”)
.toObject(参数化类型引用);
我得到一个错误:索引0:[{“id”:4

看起来Traverson希望follow引用的内容是一个链接,而不是一个嵌入对象。如何让Traverson将嵌入对象解析为一个DentalInvoices资源列表

我是否必须创建一个控制器方法,只输出可能操作的链接,以便Traverson有一个链接可以跟随