不兼容的类型错误将在升级为5.3.20之后显示

发布于 2025-01-31 09:01:53 字数 1385 浏览 5 评论 0原文

全部, 我有一个Junits的Maven Java项目: 例如:

    import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
    import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;      
 @Test
    public void test() throws Exception {
        getMockMvc().perform(put("/bla")
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .accept(MediaType.APPLICATION_JSON_VALUE)
                .characterEncoding("UTF-8")
                .content("{\n" +
                        "\n" +
                        "\"eventTypes\": [\"BLA\"]\n" +
                        "\n" +
                        "}"))
                .andExpect(jsonPath("$.eventTypes", IsCollectionWithSize.hasSize(1)));
    }

运行检查的行: JSONPATH(“ $。EventTypes”,IscollectionWithSize.Hassize(1)

JSONPATH是Spring Libary Verion 4.3.30的一部分 isCollectionWithSize.hassize是com.jayway.jsonpath.json-path-assert verion 2.4

一切正常的,直到我将春季升级到5.3.20,一切正常 错误是:

incompatible types: cannot infer type-variable(s) T,capture#79 of ? super java.util.Collection<? extends E>,E
[ERROR] (argument mismatch; org.hamcrest.Matcher<capture#80 of ? super java.util.Collection<? extends E>> cannot be converted to org.hamcrest.Matcher<? super java.lang.Object>)
[ERROR] -> [Help 1]

有人有这样的问题吗?可以提供解决方案吗?

all,
I have a maven java project with junits:
for example:

    import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
    import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;      
 @Test
    public void test() throws Exception {
        getMockMvc().perform(put("/bla")
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .accept(MediaType.APPLICATION_JSON_VALUE)
                .characterEncoding("UTF-8")
                .content("{\n" +
                        "\n" +
                        "\"eventTypes\": [\"BLA\"]\n" +
                        "\n" +
                        "}"))
                .andExpect(jsonPath("$.eventTypes", IsCollectionWithSize.hasSize(1)));
    }

the line that run the check:
jsonPath("$.eventTypes", IsCollectionWithSize.hasSize(1)

the jsonPath is part of Spring libary verion 4.3.30
and the IsCollectionWithSize.hasSize is taken form com.jayway.jsonpath.json-path-assert verion 2.4

everything worked ok until I upgraded the Spring to 5.3.20
The error is:

incompatible types: cannot infer type-variable(s) T,capture#79 of ? super java.util.Collection<? extends E>,E
[ERROR] (argument mismatch; org.hamcrest.Matcher<capture#80 of ? super java.util.Collection<? extends E>> cannot be converted to org.hamcrest.Matcher<? super java.lang.Object>)
[ERROR] -> [Help 1]

Has anyone had such a problem? And can offer a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2025-02-07 09:01:53

好的,我通过更改其中一个进口来修复它。
而不是这样:

import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;

我使用了以下方式:

import static org.hamcrest.Matchers.hasSize;

并从中更改代码:

andExpect(jsonPath("$.eventTypes", IsCollectionWithSize.hasSize(1)));

对此:

andExpect(jsonPath("$.eventTypes", hasSize(1)))

ok so I fixed it by changing one of the imports.
instead of this:

import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;

I used this:

import static org.hamcrest.Matchers.hasSize;

and change the code from this:

andExpect(jsonPath("$.eventTypes", IsCollectionWithSize.hasSize(1)));

to this:

andExpect(jsonPath("$.eventTypes", hasSize(1)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文