json: don't reserve an id when not using it
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 25 Jul 2017 15:26:50 +0000 (11:26 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 10 Aug 2017 16:10:08 +0000 (12:10 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/serialization_write.nit

index eeb30ff..d591b2e 100644 (file)
@@ -242,10 +242,10 @@ redef class Serializable
        # which is used by all the serialization engines, not just JSON.
        protected fun accept_json_serializer(v: JsonSerializer)
        do
-               var id = v.cache.new_id_for(self)
                v.stream.write "\{"
                v.indent_level += 1
                if not v.plain_json then
+                       var id = v.cache.new_id_for(self)
                        v.new_line_and_indent
                        v.stream.write "\"__kind\": \"obj\", \"__id\": "
                        v.stream.write id.to_s