Permalink
Browse files

Merge pull request #105 from c42engineering/symbolize_names

allowing symbolize_names to be used instead of symbolize_keys for compatibility with the json gem. #94
  • Loading branch information...
brianmario committed Sep 12, 2012
2 parents 5d90659 + bce57ea commit 105935e13ae565bf0273e7e5046ff37c16b2f4b3
Showing with 7 additions and 2 deletions.
  1. +2 −1 ext/yajl/yajl_ext.c
  2. +1 −1 ext/yajl/yajl_ext.h
  3. +4 −0 spec/json_gem_compatibility/compatibility_spec.rb
View
@@ -384,7 +384,7 @@ static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) {
if (rb_hash_aref(opts, sym_check_utf8) == Qfalse) {
checkUTF8 = 0;
}
- if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue) {
+ if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue || rb_hash_aref(opts, sym_symbolize_names) == Qtrue) {
symbolizeKeys = 1;
}
}
@@ -898,6 +898,7 @@ void Init_yajl() {
sym_html_safe = ID2SYM(rb_intern("html_safe"));
sym_terminator = ID2SYM(rb_intern("terminator"));
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
+ sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
#ifdef HAVE_RUBY_ENCODING_H
utf8Encoding = rb_utf8_encoding();
View
@@ -56,7 +56,7 @@ static rb_encoding *utf8Encoding;
static VALUE cParseError, cEncodeError, mYajl, cParser, cEncoder;
static ID intern_io_read, intern_call, intern_keys, intern_to_s,
intern_to_json, intern_has_key, intern_to_sym, intern_as_json;
-static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_html_safe;
+static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_symbolize_names, sym_html_safe;
#define GetParser(obj, sval) Data_Get_Struct(obj, yajl_parser_wrapper, sval);
#define GetEncoder(obj, sval) Data_Get_Struct(obj, yajl_encoder_wrapper, sval);
@@ -51,6 +51,10 @@ class Dummy; end
JSON.default_options[:symbolize_keys] = default # ensure the rest of the test cases expect the default
end
+ it "should also allow the json gem's symbolize_names key" do
+ JSON.parse('{"foo": 1234}', :symbolize_names => true).should === {:foo => 1234}
+ end
+
it "should encode arbitrary classes via their default to_json method" do
d = Dummy.new
d.to_json.should == "\"#{d.to_s}\""

0 comments on commit 105935e

Please sign in to comment.