#1932 Json bug

Akcelisto Thu 28 Jun 2012

map := Int:Int[:]
map[0] = 0    
echo(util::JsonOutStream.writeJsonToStr(map))

Result:

sys::CastErr: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
  fan.sys.Map.each (Map.java:347)
  util::JsonOutStream.writeJsonMap (JsonOutStream.fan:86)
  util::JsonOutStream.writeJson (JsonOutStream.fan:50)
  util::JsonOutStream.writeJsonToStr (JsonOutStream.fan:24)

brian Thu 28 Jun 2012

It isn't really a bug. JSON only supports string keys for its maps, and the input here is Int keys. We could potentially convert any key type to strings, but that doesn't seem like the correct behavior (better to do that outside of JSON API yourself).

SlimerDude Thu 28 Jun 2012

Could this ClassCastException not be caught and a more informative exception thrown instead? Something with a message like, "JSON only supports Str keys for maps" .

I've always been a keen believer of delivering as much context info to the developer as possible - esp when writing frameworks.

Akcelisto Fri 29 Jun 2012

+1 for more informative exception

brian Fri 29 Jun 2012

+1 for more informative exception

agreed, I pushed a fix

Login or Signup to reply.