intrude import jsonable
+in "C Header" `{
+ #define __STRICT_ANSI__
+ #include <json/json.h>
+`}
+
redef interface Jsonable
# Get a JsonObject representing this instance, specific to the C library
private fun to_json_object : JsonObject is abstract
fun to_pretty_json: String do return native_to_json(true)
fun to_json: String do return native_to_json(false)
- fun native_to_json( pretty: Bool ): String import to_json_object `{
+ fun native_to_json( pretty: Bool ): String import to_json_object, NativeString.to_s `{
json_object *jobj;
- char *json_native_string;
+ const char *json_native_string;
String json_string;
- jobj = Map_to_json_object( recv );
+ jobj = Map_of_Object_nullable_Object_to_json_object( recv );
#ifdef JSON_C_TO_STRING_PRETTY
if ( pretty )
json_native_string = json_object_to_json_string_ext( jobj, JSON_C_TO_STRING_PRETTY );
#else
json_native_string = json_object_to_json_string( jobj );
#endif
- json_string = new_String_from_cstring( json_native_string );
+ json_string = NativeString_to_s( (char*)json_native_string );
return json_string;
`}
end
end
-redef class Sequence[ E ]
+redef class SequenceRead[ E ]
redef fun to_json_object
do
var jarray = new JsonArray
end
redef class String
- redef fun to_json_object import String::from_cstring `{
+ redef fun to_json_object import NativeString.to_s, String.to_cstring `{
char *native_recv = String_to_cstring( recv );
return json_object_new_string( native_recv );
`}
new `{ return json_object_new_object(); `}
# Add a key and value to the object
- fun add( key : String, val : nullable JsonObject ) import String::to_cstring, nullable JsonObject as not nullable `{
+ fun add( key : String, val : nullable JsonObject ) import String.to_cstring, JsonObject as not nullable `{
char* native_key;
native_key = String_to_cstring( key );
- if ( JsonObject_is_null(val) ) {
+ if ( nullable_JsonObject_is_null(val) ) {
json_object_object_add( recv, native_key, NULL );
} else {
json_object *jobj;
- jobj = JsonObject_as_not_null( val );
+ jobj = nullable_JsonObject_as_JsonObject( val );
json_object_object_add( recv, native_key, jobj );
}
`}
new `{ return json_object_new_array(); `}
fun push( val : nullable JsonObject ) `{
- if ( JsonObject_is_null(val) )
+ if ( nullable_JsonObject_is_null(val) )
json_object_array_add( recv, NULL );
else
- json_object_array_add( recv, JsonObject_as_not_null(val) );
+ json_object_array_add( recv, nullable_JsonObject_as_JsonObject(val) );
`}
end