public Map<String, Object> convertValue(final Object entity, final Class<?> entityClass) {
        if (entityClass.equals(String.class)) {
            return Collections.singletonMap("data", objectMapper.convertValue(entity, String.class));
        } else if (!entityClass.equals(Void.class) && !entityClass.equals(void.class)) {
            final TypeReference<Map<String, Object>> typeRef = new TypeReference<>() {
            };
            try {
                return objectMapper.convertValue(entity, typeRef);
            } catch (IllegalArgumentException e) {
                // Try to convert the response to a list if converting to a map failed.
                final TypeReference<List<Object>> arrayTypeRef = new TypeReference<>() {
                };
                return Collections.singletonMap("data", objectMapper.convertValue(entity, arrayTypeRef));
            }
        }
        return null;
    }
@Test
    public void convertsListOfEntities() {
        final SimpleEntity firstObject = new SimpleEntity("foo", 1);
        final SimpleEntity secondObject = new SimpleEntity("bar", 42);
        final Map<String, Object> result = toTest.convertValue(Arrays.asList(firstObject, secondObject), SimpleEntity.class);
        assertNotNull(result);
        assertEquals(1, result.size());
        final Object data = result.get("data");
        assertTrue(data instanceof List);
        List dataList = (List) data;
        assertEquals(2, dataList.size());
        assertTrue(dataList.get(0) instanceof Map);
        final Map element1 = (Map) dataList.get(0);
        assertEquals("foo", element1.get("text"));
        assertEquals(1, element1.get("number"));
        assertTrue(dataList.get(1) instanceof Map);
        final Map element2 = (Map) dataList.get(1);
        assertEquals("bar", element2.get("text"));
        assertEquals(42, element2.get("number"));
    }