Sha256: bd0dfc5e838331c75c48ff6833685991633388ecebbee956cb1aa63fc35ce697
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
unless RUBY_PLATFORM =~ /java/ puts "This library is only compatible with a java-based ruby environment like JRuby." exit 255 end require_relative "jars/jrjackson-1.2.6.jar" # require_relative "linked/jrjackson-1.2.6.jar" require 'com/jrjackson/jr_jackson' module JrJackson module Json class << self TIME_REGEX = %r(\A(\d{4}-\d\d-\d\d|(\w{3}\s){2}\d\d)\s\d\d:\d\d:\d\d) def load(json_string, options = nil) if json_string.is_a?(String) && json_string =~ TIME_REGEX return JrJackson::Raw.parse_raw("\"#{json_string}\"") end if options && !options.empty? if options.size == 1 && !!options[:raw] return JrJackson::Raw.parse_raw(json_string) end if options.size == 1 && !!options[:symbolize_keys] return JrJackson::Raw.parse_sym(json_string) end JrJackson::Raw.parse(json_string, options) else JrJackson::Raw.parse_str(json_string) end end def dump(object) case object when Array, Hash, String, Java::JavaUtil::LinkedHashMap JrJackson::Raw.generate(object) when true, false object.to_s when nil 'null' else if object.respond_to?(:to_json) object.to_json elsif object.respond_to?(:to_s) object.to_s else object end end end alias :parse :load alias :generate :dump end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jrjackson-0.2.4 | lib/jrjackson/jrjackson.rb |