Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilteringParserDelegate cannot deserialize empty list #708

Closed
xiazuojie opened this issue Jul 16, 2021 · 2 comments
Closed

FilteringParserDelegate cannot deserialize empty list #708

xiazuojie opened this issue Jul 16, 2021 · 2 comments

Comments

@xiazuojie
Copy link

xiazuojie commented Jul 16, 2021

This is a follow up issue of #700 .

If using FilteringParserDelegate to filter out a part of json, it throws the following exception when the input json is an empty list ("[]").

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
 at [Source: (byte[])"[]"; line: 1, column: 2]

	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4688)
	at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:4561)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2823)
	at com.alibaba.dapr.serialization.json.FilteringParserDelegateTest.testFilteringParserDelegateWithEmptyList(FilteringParserDelegateTest.java:36)

Test case:

package com.alibaba.dapr.serialization.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertTrue;

public class FilteringParserDelegateTest {
    @Test
    public void testFilteringParserDelegateWithEmptyList() throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        final TokenFilter tokenFilter = new TokenFilter() {
            @Override
            public TokenFilter includeProperty(String name) {
                if ("@type".equals(name)) {
                    return null;
                }
                return INCLUDE_ALL;
            }
        };

        byte[] content = "[]".getBytes(StandardCharsets.UTF_8);

        JsonParser jp = mapper.createParser(content);
        JsonParser jsonParser = new FilteringParserDelegate(jp, tokenFilter, TokenFilter.Inclusion.INCLUDE_ALL_AND_PATH, true);

        List<Map<String, String>> a = mapper.readValue(jsonParser, new TypeReference<List<Map<String, String>>>() {});
        assertTrue(a.isEmpty());
    }
}

Jackson version: 2.12.3

@cowtowncoder
Copy link
Member

Interesting... empty array (and empty Object) are sort of edge cases since they are leaf values on their own.

Will need to think of what to do with them; almost certainly need to add 2 more callback methods in TokenFilter.
I hope to be able to fix this before 2.13.0 final but that may take time.

Will add failing tests first.

@cowtowncoder
Copy link
Member

Resolved via #715, to be included in 2.14.0. Closing this as dup (just for convenience as PR was pointing to the other issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants