summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-10-06 09:33:07 -0700
committertyler-ball <tyleraball@gmail.com>2014-10-06 09:33:07 -0700
commit1a626e1958a7578455e53fe2f7cc89030b3a4092 (patch)
tree3eb9a5e9a43a137291c9cf1e85304a2e0a6be0d2 /lib
parentc5d0f4c89fa5a493fd9638d232f70088b4d0556e (diff)
downloadffi-yajl-1a626e1958a7578455e53fe2f7cc89030b3a4092.tar.gz
If an object does not have .to_json, we no longer try to call it
Diffstat (limited to 'lib')
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 3df366c..a493158 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -201,7 +201,11 @@ end
# I feel dirty
class Object
def ffi_yajl(yajl_gen, state)
- json = self.to_json(state[:json_opts])
+ if self.respond_to?(:to_json)
+ json = self.to_json(state[:json_opts])
+ else
+ json = self.to_s
+ end
if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status)
end