Skip to content

Failing to parse 0 as long value when using the any api with streaming support #301

@haferjir

Description

@haferjir

I'm trying to use Jsoniter (v0.9.23) in streaming mode, but our regression suite found an issue, when parsing a json object containing a 0.

Example:

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.jsoniter.JsonIterator;
import com.jsoniter.any.Any;

public class JsonIteratorStreamingNotWorkingOnZeroTest {
    @Test
    public void minimalExampleWithStreaming() {
        JsonIterator.enableStreamingSupport();
        String json = "{\"a\":0}";
        Any any = JsonIterator.deserialize(json);
        assertEquals(0, any.get("a").toInt()); // Throws JsonException
    }
}

The code above should describe a successful test but fails with a JsonException inside IterImplForStreaming::readByte. That is because it tries to read the next byte after the zero and assert that there isn't any numbers after the 0. But the any api only provides the JsonIterator that contains the 0 and reading the next byte will fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions