fromJson method
fromJson common implementation returrns a Map buffer to caller. necessary before the Serializable subtype memory layout is known double buffers, however it should only be a small number of field reference
Implementation
// the user side class provides a function to map the values of a known memory layout/interface to the user's class' memory layout
// one point of interface to the base class
// SerializablePerson.fromMap(Map<SerializableField, Object?> base)
// : id = base[SerializablePersonField.id] as int,
// name = base[SerializablePersonField.name] as String,
// age = base[SerializablePersonField.age] as int;
//
// function composition, go through a intermediary step of jsonMap -> known memory layout/interface -> user's class, at runtime.
// Form.fromJson(json) -> StructMap -> PersonB.cast(StructMap) -> PersonB, at runtime.
// factory SerializablePerson.fromJson(Map<String, Object?> json) => SerializablePerson.fromMap(const StructForm(SerializablePersonField.values).fromJson(json));
//
// code gen can directly map jsonMap -> user class, which is most direct during runtime.
// however the code for mapping json directly to the user class, unique to each user class, would also require additional code size
FieldMap<K, V> fromJson(Map<String, Object?> json) {
return EnumMapFactory<K>(fields).fromJson<V>(json); // EnumMapFactory handles V type
}