writeValueAsString method

  1. @override
String writeValueAsString(
  1. Object? value, [
  2. ObjectMapperType mapWith = ObjectMapperType.JSON
])
override

Serializes a Dart object into a structured format string.

The format can be JSON, YAML, XML, or any supported representation depending on the configuration or generator provided.

The active NamingStrategy, annotations, and converters are applied.

Example

final dataString = mapper.writeValueAsString(user); 

Implementation

@override
String writeValueAsString(Object? value, [ObjectMapperType mapWith = ObjectMapperType.JSON]) {
  if (value == null) return "";

  if (mapWith == ObjectMapperType.XML) {
    return writeValueAsXml(value);
  }

  if (mapWith == ObjectMapperType.YAML) {
    return writeValueAsYaml(value);
  }

  return writeValueAsJson(value);
}