// ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes import 'dart:convert'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; part 'content_string.g.dart'; abstract class ContentString implements Built, ContentStringBuilder> { factory ContentString([final void Function(ContentStringBuilder)? b]) = _$ContentString; const ContentString._(); /// decoded contentString T get content; static Serializer> get serializer => _$contentStringSerializer; } class ContentStringPlugin implements SerializerPlugin { const ContentStringPlugin(); @override Object? afterDeserialize(final Object? object, final FullType specifiedType) => object; @override Object? afterSerialize(final Object? object, final FullType specifiedType) { if (!specifiedType.root.toString().contains('ContentString')) { return object; } if (object is! Map) { throw ArgumentError('ContentStringPlugin can only be applied to Map. ' 'Please ensure the StandardJsonPlugin is applied and run before.'); } final content = object['content']; return jsonEncode(content); } @override Object? beforeDeserialize(final Object? object, final FullType specifiedType) { if (!specifiedType.root.toString().contains('ContentString')) { return object; } if (object is! String) { throw ArgumentError('The serialized ContentString must be of type String. ' 'Please ensure the StandardJsonPlugin is applied and run before.'); } final content = jsonDecode(object); return ['content', content]; } @override Object? beforeSerialize(final Object? object, final FullType specifiedType) => object; }