diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-07 15:58:18 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-07 15:58:18 -0700 |
commit | 6e19eb693350f198f9b18609c3f1a89b3138b79e (patch) | |
tree | 41e85ca3d6b4dfa79b63c0d31f07116b8f141a18 /lib/ffi_yajl | |
parent | c5d0f4c89fa5a493fd9638d232f70088b4d0556e (diff) | |
parent | d713d2681aba154fc83d41b32bbdbb99c2055b61 (diff) | |
download | ffi-yajl-6e19eb693350f198f9b18609c3f1a89b3138b79e.tar.gz |
Merge pull request #25 from tyler-ball/tball/remove_to_json
If an object does not have .to_json, we no longer try to call it
Diffstat (limited to 'lib/ffi_yajl')
-rw-r--r-- | lib/ffi_yajl/ffi/encoder.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 3df366c..8177f5f 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -201,8 +201,15 @@ end # I feel dirty class Object def ffi_yajl(yajl_gen, state) - json = self.to_json(state[:json_opts]) - if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) ) != 0 + if self.respond_to?(:to_json) + json = self.to_json(state[:json_opts]) + # #yajl_gen_number outputs a string without quotes around it + status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) + else + str = self.to_s + status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) + end + if ( status ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status) end end |