wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
292 stars 55 forks source link

Property binding not working when it's coupled with a filtered binding #59

Closed maciesse closed 4 years ago

maciesse commented 4 years ago

Hi,

I found a strange behaviour, not sure if it's a bug or it's just me using the API in the wrong manner. (At least) With JsonSurfer and FastJsonParser, if I try this code

public void testStrangeBehavihour() throws Exception {
        surfer.configBuilder()
                .bind("$.store.book[?(@.category == 'reference')]", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        System.out.println(value);
                    }
                })
                .bind("$.store.bicycle.color", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        System.out.println(value); //This never happen
                    }
                })
                .bind("$.store.bicycle", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        System.out.println(value);
                    }
                }).buildAndSurf(read("sample.json"));
    }

the second listener will never be called.

If I remove the first binding everything works well:

    public void testStrangBehavihour() throws Exception {
        surfer.configBuilder()
                .bind("$.store.bicycle.color", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        System.out.println(value);
                    }
                })
                .bind("$.store.bicycle", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        System.out.println(value);
                    }
                }).buildAndSurf(read("sample.json"));
    }

I tried to find an explanation in the code but found nothing.

wanglingsong commented 4 years ago

Which version?

maciesse commented 4 years ago

Latest 1.5.1

wanglingsong commented 4 years ago

Could you provide the "sample.json" as well?

maciesse commented 4 years ago

It's the one used for the unit tests

wanglingsong commented 4 years ago

Sorry for the late reply. I was quite busy recently. Previous commit should fix this issue. Please check.

maciesse commented 4 years ago

It works, thanks!