diff options
Diffstat (limited to 'java/src/json/ext/Generator.java')
-rw-r--r-- | java/src/json/ext/Generator.java | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index ecceb27..bb3a394 100644 --- a/java/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java @@ -1,8 +1,7 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. * - * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files - * for details. + * Distributed under the Ruby license: https://www.ruby-lang.org/en/about/license.txt */ package json.ext; @@ -428,11 +427,14 @@ public final class Generator { new Handler<IRubyObject>() { @Override RubyString generateNew(Session session, IRubyObject object) { - IRubyObject result = - object.callMethod(session.getContext(), "to_json", - new IRubyObject[] {session.getState()}); - if (result instanceof RubyString) return (RubyString)result; - throw session.getRuntime().newTypeError("to_json must return a String"); + if (object.respondsTo("to_json")) { + IRubyObject result = object.callMethod(session.getContext(), "to_json", + new IRubyObject[] {session.getState()}); + if (result instanceof RubyString) return (RubyString)result; + throw session.getRuntime().newTypeError("to_json must return a String"); + } else { + return OBJECT_HANDLER.generateNew(session, object); + } } @Override |