3

I have a rest endpoint which returns List<VariablePresentation>. I am trying to test this rest endpoint 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 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 issue?

1 Answer 1

6

That looks like a Jackson error, where it's expecting to parse an array (which would begin with a '[') but it's encountering the beginning token for an object ('{'). From looking at your code, Im guessing it's trying deserialise JSON into your List but it's getting the JSON for an object.

What does the JSON your REST endpoint returns look like? It ought to look like this

[ { // JSON for VariablePresentation value 0 "field0": <some-value> <etc...> }, <etc...> ] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.