lib/popcorn: fix serialization of validation errors
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 16 May 2017 20:41:50 +0000 (16:41 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 16 May 2017 23:19:28 +0000 (19:19 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/popcorn/pop_validation.nit

index aebbc93..ad66fb5 100644 (file)
@@ -140,20 +140,15 @@ class ValidationResult
        # Does `self` contains `errors`?
        fun has_error: Bool do return errors.not_empty
 
-       # Render self as a JsonObject
-       fun json: JsonObject do
-               var obj = new JsonObject
-               obj["has_error"] = has_error
-               var e = new JsonObject
-               for k, v in errors do
-                       e[k] = new JsonArray.from(v)
-               end
-               obj["errors"] = e
-               return obj
+       redef fun core_serialize_to(v) do
+               var errors = new JsonObject
+               for k, e in self.errors do
+                       errors[k] = new JsonArray.from(e)
+               end
+               v.serialize_attribute("has_error", has_error)
+               v.serialize_attribute("errors", errors)
        end
 
-       redef fun serialize_to(v) do json.serialize_to(v)
-
        # Returns the validation result as a pretty formated string
        fun to_pretty_string: String do
                var b = new Buffer