benchs: protect mangle groups of options in `bench_nitg*_options`
[nit.git] / lib / json / json_writer.nit
index d568140..41454a0 100644 (file)
@@ -15,6 +15,11 @@ module json_writer
 
 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
@@ -26,12 +31,12 @@ redef class Map[ K, V ]
        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 );
@@ -40,7 +45,7 @@ redef class Map[ K, V ]
 #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;
        `}
 
@@ -71,7 +76,7 @@ redef class Map[ K, V ]
        end
 end
 
-redef class Sequence[ E ]
+redef class SequenceRead[ E ]
        redef fun to_json_object
        do
                var jarray = new JsonArray
@@ -93,7 +98,7 @@ redef class Sequence[ E ]
 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 );
        `}
@@ -121,16 +126,16 @@ redef class JsonObject
        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 );
                }
        `}
@@ -142,9 +147,9 @@ private extern JsonArray
        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