* the result. If no valid JSON document can be created this method raises
* a GeneratorError exception.
*/
@JRubyMethod
public IRubyObject generate(ThreadContext context, IRubyObject obj) {
RubyString result = Generator.generateJson(context, obj, this);
if (!quirksMode && !objectOrArrayLiteral(result)) {
throw Utils.newException(context, Utils.M_GENERATOR_ERROR,
"only generation of JSON objects or arrays allowed");
}
RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
if (info.encodingsSupported()) {
result.force_encoding(context, info.utf8.get());
}
return result;
}