Skip to content

Any iteration broken #233

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

Closed
ratcashdev opened this issue Apr 12, 2019 · 1 comment
Closed

Any iteration broken #233

ratcashdev opened this issue Apr 12, 2019 · 1 comment

Comments

@ratcashdev
Copy link

the following test fails

public void test_Iteration() {
        Any o1 = JsonIterator.deserialize("{\"prop\":\"asd\",\"prop2\":123}");
        assertThat(o1, is(not(nullValue())));

        int entryCounter = 0;
        for(Any obj : o1) {
            entryCounter++;
        }
        assertThat(entryCounter, is(equalTo(2)));        
    }
@ratcashdev
Copy link
Author

I have realized that o1.iterator() is not meaningful given that o1 is a JSON Object (and not an array, for example).
The proper way to iterate is:

public void test_Iteration() {
        Any o1 = JsonIterator.deserialize("{\"prop\":\"asd\",\"prop2\":123}");
        assertThat(o1, is(not(nullValue())));
        
        int entryCounter = 0;
        Any.EntryIterator iter = o1.entries();
        while (iter.next()) {
            entryCounter++;
        }
        
        assertThat(entryCounter, is(equalTo(2)));        
    }

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

1 participant