Method: Oj.register_odd_raw
- Defined in:
- ext/oj/oj.c
.register_odd_raw(clas, create_object, create_method, dump_method) ⇒ Object
Registers a class as special and expect the output to be a string that can be included in the dumped JSON directly. This is useful for working around subclasses of primitive types as is done with ActiveSupport classes. The use of this function should be limited to just classes that can not be handled in the normal way. It is not intended as a hook for changing the output of all classes as it is not optimized for large numbers of classes. Be careful with this option as the JSON may be incorrect if invalid JSON is returned.
-
clas [Class|Module] Class or Module to be made special
-
create_object [Object] object to call the create method on
-
create_method [Symbol] method on the clas that will create a new instance of the clas when given all the member values in the order specified.
-
dump_method [Symbol|String] method to call on the object being serialized to generate the raw JSON.
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
# File 'ext/oj/oj.c', line 1484
static VALUE register_odd_raw(int argc, VALUE *argv, VALUE self) {
if (3 > argc) {
rb_raise(rb_eArgError, "incorrect number of arguments.");
}
switch (rb_type(*argv)) {
case T_CLASS:
case T_MODULE: break;
default: rb_raise(rb_eTypeError, "expected a class or module."); break;
}
Check_Type(argv[2], T_SYMBOL);
if (MAX_ODD_ARGS < argc - 2) {
rb_raise(rb_eArgError, "too many members.");
}
oj_reg_odd(argv[0], argv[1], argv[2], 1, argv + 3, true);
return Qnil;
}
|