#647 Proposed Project-Haystack Java Toolkit JSONWriter fix

Jonathan Hughes Wed 24 Oct 2018

Was attempting to use the HJsonwriter and found a few deficiencies with it's ability to write valid HGrid's into a valid JSON string. Here are a few proposed updates to the java haystack toolkit to correct these issues.

  1. If the value of a tag in an HDict was also an HDict, the HDict.toJSON method fails. Corrected by adding the line in the method private void writeVAl(HVal val)
    Add after Line 118: else if (val instanceof HBool) out.print(val);
    else if(val instanceof HDict) writeDict((HDict) val);
  2. Similarly if the value of the tag is an HGrid, the same issue presents itself. Corrected by adding after line added from above:
    else if(val instanceof HGrid) writeGrid((HGrid) val);

Which would turn the existing method:

private void writeVal(HVal val)
{
  if (val == null) out.print("null");
  else if (val instanceof HBool) out.print(val);
  else out.print(HStr.toCode(val.toJson()));
}

Into:

private void writeVal(HVal val)
{
  if (val == null) out.print("null");
  else if (val instanceof HBool) out.print(val);
  else if(val instanceof HDict) writeDict((HDict) val);
  else if(val instanceof HGrid) writeGrid((HGrid) val);
  else out.print(HStr.toCode(val.toJson()));
}

3.HJSonwriter needs to respect the meta version defined in the grid. Currently it is hard coded to 2.

Matthew Giannini Thu 25 Oct 2018

Hi Jonathan - I'll take a look at these issues and your proposed solutions. If you would like to submit a pull request with your fixes I could also look at that.

Jonathan Hughes Thu 25 Oct 2018

Pull request HJSonWriter Enhancements has been submitted.

Matthew Giannini Fri 26 Oct 2018

I merged in your pull request and made a few minor tweaks. Thanks!

Jonathan Hughes Fri 26 Oct 2018

Thanks for accepting. Now it's time to update my master repo.

Login or Signup to reply.