self
to JSONSet plain = true
to generate standard JSON, without deserialization metadata.
Use this option if the generated JSON will be read by other programs or humans.
Use the default, plain = false
, if the JSON is to be deserialized by a Nit program.
Set pretty = true
to generate pretty JSON for human eyes.
Use the default, pretty = false
, to generate minified JSON.
This method should not be refined by subclasses,
instead accept_json_serializer
can customize the serialization of an object.
See: JsonSerializer
# Serialize `self` to JSON
#
# Set `plain = true` to generate standard JSON, without deserialization metadata.
# Use this option if the generated JSON will be read by other programs or humans.
# Use the default, `plain = false`, if the JSON is to be deserialized by a Nit program.
#
# Set `pretty = true` to generate pretty JSON for human eyes.
# Use the default, `pretty = false`, to generate minified JSON.
#
# This method should not be refined by subclasses,
# instead `accept_json_serializer` can customize the serialization of an object.
#
# See: `JsonSerializer`
fun serialize_to_json(plain, pretty: nullable Bool): String
do
var stream = new StringWriter
var serializer = new JsonSerializer(stream)
serializer.plain_json = plain or else false
serializer.pretty_json = pretty or else false
serializer.serialize self
stream.close
return stream.to_s
end
lib/json/serialization_write.nit:201,2--223,4