SerdesGenerator<FieldAnnotation extends FieldSerializable, _SiblingModel extends Model> class
abstract
A generator that converts raw input into Dart code or Dart code into raw input. Most
Provider
s will require a SerdesGenerator
to help the Repository normalize data.
FieldAnnotation
describes the field-level class, such as @Rest
_SiblingModel
describes the domain or provider model, such as SqliteModel
Constructors
-
SerdesGenerator(ClassElement element, FieldsForClass<
FieldAnnotation> fields)
Properties
- adapterMethod → String
-
The method as printed by the adapter. Does not include semicolon.
no setter
- adapterMethodInputType → String
-
The expected input type for the adapterMethod
no setter
- adapterMethodOutputType → String
-
The expected output type of the adapterMethod
no setter
- className → String
-
no setter
- constructorName → String
-
Discover factories within the class that rely on the provider.
For example
factory User.fromRest
no setter - deserializeInputType → String
-
The Type expected from the provider when deserializing
no setter
- doesDeserialize → bool
-
Whether this generator serializes or deserializes raw input
no setter
- element → ClassElement
-
The annotated class
final
-
fields
→ FieldsForClass<
FieldAnnotation> -
The sorted fields of the element
final
- fieldsForGenerator → String
-
Mash the element's fields into a list for serialization or deserialization
no setter
- generateSuffix → String
-
Code to follow after a class has been instantiated.
Must end with semicolon.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
instanceFieldsAndMethods
→ List<
String> -
Any instance fields that should be copied to the adapter.
Should terminate in
;
if required.no setter - providerName → String
-
For example,
Rest
orSqlite
no setter - repositoryHasBeenForceCast ↔ bool
-
Avoid linter error on subsequent passes for the repository.
For example, if repository has already been casted to
!
it should not be recastgetter/setter pair - repositoryName → String
-
For example,
OfflineFirst
no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serializeMethod → String
-
Discover serializers within the class that rely on the provider.
For example
toRest() =>
no setter - serializeOutputType → String
-
The Type expected by the provider when serializing
no setter
- serializingFunctionArguments → String
-
Expected arguments for the serializing/deserializing function.
Does not include parentheses.
no setter
- serializingFunctionName → String
-
The generated deserialize function name
no setter
-
unignoredFields
→ Iterable<
FieldElement> -
All fields that are serializable by this generator and are not declared
to be ignored by an annotation.
no setter
Methods
-
addField(
FieldElement field, FieldAnnotation fieldAnnotation) → String? -
Given each field, determine whether it can be added to the serdes function
and, more importantly, determine how it should be added. If the field should not
be added, return
null
. -
checkerForField(
FieldElement field) → SharedChecker< Model> -
Return a
SharedChecker
for a type via the corresponding parameter in the constructor. -
checkerForType(
DartType type) → SharedChecker< Model> -
Return a
SharedChecker
for a type. If including a custom checker in your domain, overwrite this field -
coderForField(
FieldElement field, SharedChecker< Model> checker, {required FieldAnnotation fieldAnnotation, required bool wrappedInFuture}) → String? - Produces serializing or deserializing method given a field and checker.
-
deserializerNullableClause(
{required FieldElement field, required FieldAnnotation fieldAnnotation, required String name}) → String - Injected between the field member in the constructor and the contents
-
digestPlaceholders(
String? input, String annotatedName, String fieldName) → String? - Replace default placeholders
-
expandGenerators(
FieldAnnotation annotation, {required FieldElement field, required SharedChecker< Model> checker}) → String? -
Convert placeholders in
fromGenerator
andtoGenerator
to functions. -
generate(
) → String - Wraps fieldsForGenerator in a method to produce serialization or deserialization
-
getAssociationMethod(
DartType argType, {bool forceNullable = false, required String query}) → String -
hasConstructor(
DartType type) → bool -
If this class possesses a factory such as
fromRest
-
hasSerializer(
DartType type) → bool -
If this class possesses a serializing method such as
toSqlite
-
ignoreCoderForField(
FieldElement field, FieldAnnotation annotation, SharedChecker< Model> checker) → bool - Determine whether this field should be included in generated output.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
providerNameForField(
String? annotatedName, {required SharedChecker< Model> checker}) → String - The field's name when being serialized to a provider. Optionally, a checker can reveal the field's purpose.
-
serdesValueForField(
FieldElement field, String annotatedName, {required SharedChecker< Model> checker}) → String -
The field's value when used by the generator.
For example,
data['my_field']
when used by a deserializing generator orinstance.myField
when used by a serializing generator -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
defaultValueSuffix(
FieldSerializable fieldAnnotation) → String -
If the annotation includes a
defaultValue
, use it when the received value is null -
digestCustomGeneratorPlaceholders(
String input) → String -
If a custom generator is provided, replace variables with desired values
Useful for hacking around
const
functions when duplicating logic -
iterableCast(
DartType argType, {bool isSet = false, bool isList = false, bool isFuture = false, bool forceCast = false}) → String - Cast mapped values to their desired output value