json: avoid repeating if condition
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 3 Aug 2017 16:46:42 +0000 (12:46 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 10 Aug 2017 16:18:10 +0000 (12:18 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/serialization_write.nit

index d591b2e..8f3c2d1 100644 (file)
@@ -317,8 +317,10 @@ end
 redef class SimpleCollection[E]
        redef fun accept_json_serializer(v)
        do
-               # Register as pseudo object
-               if not v.plain_json then
+               if v.plain_json then
+                       serialize_to_pure_json v
+               else
+                       # Register as pseudo object
                        var id = v.cache.new_id_for(self)
                        v.stream.write """{"""
                        v.indent_level += 1
@@ -329,14 +331,12 @@ redef class SimpleCollection[E]
                        v.stream.write class_name
                        v.stream.write """","""
                        v.new_line_and_indent
+
                        v.stream.write """"__items": """
                        serialize_to_pure_json v
+
                        core_serialize_to v
-               else
-                       serialize_to_pure_json v
-               end
 
-               if not v.plain_json then
                        v.indent_level -= 1
                        v.new_line_and_indent
                        v.stream.write "\}"