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 7894575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:25:50+00:00 2026-06-03T07:25:50+00:00

I’m trying to figure out if this is a bug within HtmlJson.java or in

  • 0

I’m trying to figure out if this is a bug within HtmlJson.java or in my implementation. I just upgraded to PlayN version 1.2. My code attempts to load a Json.Object into a Json.Writer. This works in the Java version.

This is the code below. The exception is raised by line jsonWriter.object(jsonData); (note comment in code):

private void loadStoredData() {
    // storage parameters
    String storageKey = "jsonData";
    Json.Object jsonData = PlayN.json().createObject();        

    // attempt to load stored data
    String jsonString = PlayN.storage().getItem(storageKey);

    // if not loaded, create stored data
    if ( jsonString == null ) {
        DemoApi.log("stored data not found");
        jsonData.put("firstWrite", new Date().toString());

    // else display data
    } else {
        jsonData = PlayN.json().parse(jsonString);
        DemoApi.log("stored data loaded");
        DemoApi.log("data first written at " + jsonData.getString("firstWrite"));
        DemoApi.log("data last read at " + jsonData.getString("lastRead"));
        DemoApi.log("data last written at " + jsonData.getString("lastWrite"));
    }

    // update last read
    jsonData.put("lastRead", new Date().toString());

    // write data
    Json.Writer jsonWriter = PlayN.json().newWriter();
    jsonWriter.object(jsonData);        // <--- EXCEPTION RAISED HERE
    jsonString = jsonWriter.write();

    // store data as json
    PlayN.storage().setItem(storageKey, jsonString);

    // confirm
    if ( PlayN.storage().isPersisted() ) {
        DemoApi.log("data successfully persisted");
    } else {
        DemoApi.log("failed to persist data");
    }
}

The exception:

ERROR: Uncaught Exception: 
java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to java.lang.String
    at playn.html.HtmlJson$HtmlObject$.write$(HtmlJson.java:356)
    at com.google.gwt.core.client.JavaScriptObject$.playn_core_Json$Object_write(JavaScriptObject.java)
    at playn.core.json.JsonWriterBase.object(JsonWriterBase.java:119)
    at playn.core.json.JsonWriterBase.object(JsonWriterBase.java:90)
    at klenwell.sandbox.core.controllers.SandboxController.loadStoredData(SandboxController.java:121)

If this is a bug in my code, how might I correct it?

  • 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-03T07:25:51+00:00Added an answer on June 3, 2026 at 7:25 am

    I found an alternative. Not quite as elegant as the original code, but it tested successfully in HTML5:

    private void loadStoredData() {
        // storage parameters
        String storageKey = "jsonData";
        Json.Object jsonData = PlayN.json().createObject();  
    
        // to reset storage, uncomment this line
        //PlayN.storage().removeItem(storageKey);
    
        // attempt to load stored data
        String jsonString = PlayN.storage().getItem(storageKey);
    
        // if not loaded, create stored data
        if ( jsonString == null ) {
            DemoApi.log("stored data not found");
            jsonData.put("firstWrite", new Date().toString());
    
        // else display data
        } else {
            jsonData = PlayN.json().parse(jsonString);
            DemoApi.log("stored data loaded");
            DemoApi.log("data first written at " + jsonData.getString("firstWrite"));
            DemoApi.log("data last read at " + jsonData.getString("lastRead"));
            DemoApi.log("data last written at " + jsonData.getString("lastWrite"));
        }
    
        // update last read
        jsonData.put("lastRead", new Date().toString());
    
        // write data (this works in Java -- not in HTML)
        // see http://stackoverflow.com/q/10425877/1093087
        /*
        Json.Writer jsonWriter = PlayN.json().newWriter();
        jsonWriter.object(jsonData).end();
        jsonString = jsonWriter.write();
        */
    
        // alternative write routine
        Json.Writer jsonWriter = PlayN.json().newWriter();
        jsonWriter.object();
        for ( String key : jsonData.keys() ) {
            jsonWriter.value(key, jsonData.getString(key));
        }
        jsonWriter.end();
        jsonString = jsonWriter.write();
    
        // store data as json
        PlayN.storage().setItem(storageKey, jsonString);
    
        // confirm
        if ( PlayN.storage().isPersisted() ) {
            DemoApi.log("data successfully persisted");
        } else {
            DemoApi.log("failed to persist data");
        }
    }
    

    DemoApi.log, for the record, is a method I hatched to log output to the screen when testing in the browser. I later discovered that the PlayN.log() service logs to the Chrome console fine.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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 just tried to save a simple *.rtf file with some websites and

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.