Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:38:01+00:00 2026-06-04T00:38:01+00:00

I’m trying to implement JSON array iterator with Jackson SAX parser (please, don’t ask

  • 0

I’m trying to implement JSON array iterator with Jackson SAX parser (please, don’t ask why).
My app should work with huge files (up to 5 MiB), and that’s a problem.

That’s how I initialize JsonParser and call iterator creation.
I create InputStream initialized with JSON placed in \raw folder.

    private JsonArrayIterator getIterator(String needle) throws IOException
    {
        InputStream inputStream = getApplicationContext().getResources().openRawResource(R.raw.products);
        inputStream.mark(-1);

        try {
        JsonParser jsonParser = createJsonParser(inputStream);

        // Some unrelated code

        return new JsonArrayIterator(jsonParser);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        inputStream.close();
    }

        return null;
    }

And here is my iterator class.


    private Object parseNextObject() throws IOException {
        // I'm not using ObjectMapper because of reasons
        HashMap nextObject = new HashMap();

        int objectsCount = 1;

        while (objectsCount > 0) {
            JsonToken currentToken = currentParser.nextValue();

            if(currentToken == JsonToken.START_OBJECT) {
                ++objectsCount;
            }
            else if(currentToken == JsonToken.END_OBJECT) {
                --objectsCount;
            }
            else if(currentToken == JsonToken.START_ARRAY) {
                String currentName = currentParser.getCurrentName();
                ArrayList list = new ArrayList(100);
                JsonArrayIterator it = new JsonArrayIterator(currentParser);

                while (it.hasNext()) {
                    list.add(it.next());
                }

                nextObject.put(currentName, list);
            }
            else {
                // Here exception is throwed
                nextObject.put(currentParser.getCurrentName(), currentParser.getText());
            }
        }

        currentParser.nextToken();  // Skip END_OBJECT
        return nextObject;
    }

It seem to work perfe… OH, WAIT.

I have 3 sections (named arrays) in some huge file.
It successfully parses first (a tiny one, under 1000 bytes). But I can’t parse next.

Next array has nested array with simple objects (like this):


    {
        "properties":[
            {
                "id":"1",
                "title":"\u0426\u0432\u0435\u0442",
                "values":[
                    {
                        "id":"1_2",
                        "title":"\u0427\u0435\u0440\u043d\u044b\u0439"
                    },
                    {
                        "id":"1_5005",
                        "title":"\u0417\u0435\u043b\u0435\u043d\u044b\u0439"
                    },
                    {
                        "id":"1_5006",
                        "title":"\u0421\u0435\u0440\u044b\u0439"
                    }
                ]
            }
        ]
    }

For one object in values I call nextObject.put. currentParser.getCurrentName() is runs successfully and returns correct string, but currentParser.getText() fails. It’s not a JSON problem: it perfectly being mapped on iOS. It’s not an object or iterator creation problem: I can delete that where parser throws exception, but it will fail in the same place.

Here is stack trace:


    05-15 21:57:28.617: ERROR/AndroidRuntime(14758): FATAL EXCEPTION: main
    java.lang.NullPointerException: asset
    at android.content.res.AssetManager.readAsset(Native Method)
    at android.content.res.AssetManager.access$700(AssetManager.java:36)
    at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:576)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.loadMore(UTF8StreamJsonParser.java:174)
    at com.fasterxml.jackson.core.base.ParserBase.loadMoreGuaranteed(ParserBase.java:425)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:1930)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString(UTF8StreamJsonParser.java:1911)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.getText(UTF8StreamJsonParser.java:276)
    at ru.studiomobile.JsonArrayIterator.parseNextObject(JsonArrayIterator.java:57)
    at ru.studiomobile.JsonArrayIterator.next(JsonArrayIterator.java:73)
    at ru.studiomobile.JsonArrayIterator.parseNextObject(JsonArrayIterator.java:47)
    at ru.studiomobile.JsonArrayIterator.next(JsonArrayIterator.java:73)
    at ru.studiomobile.MainActivity$2.onClick(MainActivity.java:81)
    at android.view.View.performClick(View.java:3127)
    at android.view.View$PerformClick.run(View.java:12025)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4126)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)

I noticed that there are something called Utf8StreamJsonParser. It has a field named _inputEnd equal 4000 (why 4000?). When other field, _inputPtr, become bigger it throw an exception. How do I can handle it? I tried to use BufferedInputStream with predefined block size instead of InputStream but it had no effect.

Update

Info about some lines


    47: list.add(it.next());  
    73: return parseNextObject();  
    75: e.printStackTrace();

Nothing special.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:38:03+00:00Added an answer on June 4, 2026 at 12:38 am

    It was an obvious problem: I forgot that I close stream after creating parser…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.