Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ext/yajl/yajl_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
keys = rb_funcall(obj, intern_keys, 0);
for(idx=0; idx<RARRAY_LEN(keys); idx++) {
entry = rb_ary_entry(keys, idx);
keyStr = rb_funcall(entry, intern_to_s, 0); /* key must be a string */
/* key must be encoded as a string */
if(RB_TYPE_P(entry, T_STRING) || RB_TYPE_P(entry, T_SYMBOL)) {
keyStr = entry;
} else {
keyStr = rb_funcall(entry, intern_to_s, 0);
}
/* the key */
yajl_encode_part(w, keyStr, io);
/* the value */
Expand All @@ -194,6 +199,11 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
CHECK_STATUS(yajl_gen_bool(w->encoder, 0));
break;
case T_FIXNUM:
str = rb_fix2str(obj, 10);
cptr = RSTRING_PTR(str);
len = RSTRING_LEN(str);
CHECK_STATUS(yajl_gen_number(w->encoder, cptr, len));
break;
case T_FLOAT:
case T_BIGNUM:
str = rb_funcall(obj, intern_to_s, 0);
Expand All @@ -209,6 +219,12 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
len = RSTRING_LEN(obj);
CHECK_STATUS(yajl_gen_string(w->encoder, (const unsigned char *)cptr, len));
break;
case T_SYMBOL:
str = rb_id2str(SYM2ID(obj));
cptr = RSTRING_PTR(str);
len = RSTRING_LEN(str);
CHECK_STATUS(yajl_gen_string(w->encoder, (const unsigned char *)cptr, len));
break;
default:
if (rb_respond_to(obj, intern_to_json)) {
str = rb_funcall(obj, intern_to_json, 0);
Expand Down