RestEasy: org.codehaus.jackson.map.JsonMappingException: Unable to deserialize java.util.ArrayList instance from START_OBJECT (..) token

I have a resting endpoint that returns List<VariablePresentation>

. I am trying to test this endpoint breakpoint as

    @Test
    public void testGetAllVariablesWithoutQueryParamPass() throws Exception {
        final ClientRequest clientCreateRequest = new ClientRequest("http://localhost:9090/variables");
        final MultivaluedMap<String, String> formParameters = clientCreateRequest.getFormParameters();
        final String name = "testGetAllVariablesWithoutQueryParamPass";
        formParameters.putSingle("name", name);
        formParameters.putSingle("type", "String");
        formParameters.putSingle("units", "units");
        formParameters.putSingle("description", "description");
        formParameters.putSingle("core", "true");

        final GenericType<List<VariablePresentation>> typeToken = new GenericType<List<VariablePresentation>>() {
        };
        final ClientResponse<List<VariablePresentation>> clientCreateResponse = clientCreateRequest.post(typeToken);
        assertEquals(201, clientCreateResponse.getStatus());
        final List<VariablePresentation> variables = clientCreateResponse.getEntity();
        assertNotNull(variables);
        assertEquals(1, variables.size());

    }

      

This test fails with an error saying

org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token(..)

      

How can I fix this problem?

+3


source to share


1 answer


This looks like a Jackson bug where he expects to parse an array (which starts with "["), but he encounters an initial token for the object ('{'). From looking at your code, I am assuming it is trying to deserialize JSON into your list, but it is getting JSON for an object.

What does your REST endpoint return JSON? It should look like this.



[
    {
        // JSON for VariablePresentation value 0
        "field0": <some-value>
        <etc...>
    },
    <etc...>
]

      

+6


source







All Articles