Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allowing symbolize_names to be used instead of symbolize_keys for compatibility with the json gem. #94 #105

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. @srushti

    allowing symbolize_names to be used instead of symbolize_keys for com…

    srushti authored
    …patibility with the json gem. #94
This page is out of date. Refresh to see the latest.
View
3  ext/yajl/yajl_ext.c
@@ -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
4 ext/yajl/yajl_ext.h
@@ -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) (sval = (yajl_parser_wrapper*)DATA_PTR(obj));
#define GetEncoder(obj, sval) (sval = (yajl_encoder_wrapper*)DATA_PTR(obj));
@@ -132,4 +132,4 @@ static VALUE rb_yajl_json_ext_false_to_json(int argc, VALUE * argv, VALUE self);
static VALUE rb_yajl_json_ext_nil_to_json(int argc, VALUE * argv, VALUE self);
static VALUE rb_yajl_encoder_enable_json_gem_ext(VALUE klass);
-void Init_yajl();
+void Init_yajl();
View
4 spec/json_gem_compatibility/compatibility_spec.rb
@@ -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}\""
Something went wrong with that request. Please try again.