Hi,
I raised this on stackoverflow - but wondering if its perhaps a jruby
bug (or feature)
I have a Java HashMap that I have in JRuby, I am trying to convert it to
JSON, but its not converting correctly, I think this example shows the
problem:
$ irb
irb(main):001:0> require 'java'
=> false
irb(main):003:0> require 'json'
=> true
irb(main):005:0> h = java.util.HashMap.new()
=> {}
irb(main):006:0> x = {}
=> {}
irb(main):007:0> JSON.parse JSON.dump x
=> {}
irb(main):008:0> JSON.parse JSON.dump h
JSON::ParserError: unexpected token at '"{}"'
from json/ext/Parser.java:251:in `parse'
from
/Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/json/common.rb:155:in
parse' from (irb):9:in
evaluate’
from org/jruby/RubyKernel.java:1066:in eval' from org/jruby/RubyKernel.java:1409:in
loop’
from org/jruby/RubyKernel.java:1174:in catch' from org/jruby/RubyKernel.java:1174:in
catch’
from /Users/kimptoc/.rvm/rubies/jruby-1.7.3/bin/irb:13:in
`(root)’
irb(main):010:0> JSON.dump h
=> “"{}"”
Any ideas on how to handle this - do I need to turn the map into a Ruby
map?
There are some more subtleties around this too
-
The map is actually a synchronizedMap, which Jruby doesnt seem to
think is a Hash - so currently I wrap it in a HashMap to make it more
Jruby friendly
-
Sub maps also have the issue (perhaps obviously, I guess)
Should I raise a bug, or is this one of those, thats how it is features
Thanks,
Chris
This email (including any attachments to it) is confidential, legally
privileged, subject to copyright and is sent for the personal attention
of the intended recipient only. If you have received this email in
error, please advise us immediately and delete it. You are notified that
disclosing, copying, distributing or taking any action in reliance on
the contents of this information is strictly prohibited. Although we
have taken reasonable precautions to ensure no viruses are present in
this email, we cannot accept responsibility for any loss or damage
arising from the viruses in this email or attachments. We exclude any
liability for the content of this email, or for the consequences of any
actions taken on the basis of the information provided in this email or
its attachments, unless that information is subsequently confirmed in
writing.