New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework serialization #327
Rework serialization #327
Conversation
@fischerscode Hi! I saw the PR. Unfortunately, I won't have time to look through it in detail until Friday this week as I'm preparing a large Flutter/Serverpod event in Stockholm on Thursday. Overall, your work looks very cool. Love the idea of making the serialization compatible with Freezed and many of your other improvements. Would you be available for a quick chat on video sometime next days? Would love to synch up. Feel free to add me on Linkedin and we can take it from there: https://www.linkedin.com/in/viktorlidholt/ |
I created a new branch for this with my updates here: I fixed most of the issues now. I think that the only thing left to do is the custom constructors. |
This reverts commit d30ae38.
for (var sessionCallback in channel) { | ||
try { | ||
sessionCallback(message); | ||
} on TypeError catch (_) { | ||
// Ignore since the developer has added callbacks taking different types to this Channel. | ||
} catch (e, stackTrace) { | ||
sessionCallback.session.log( | ||
'Failed to execute callback in channel $channelName', | ||
exception: e, | ||
level: LogLevel.error, | ||
stackTrace: stackTrace, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have added this part. Should I readd it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure that you are pulling my changes before you make any new edits.
This PR points to your branch now.
I'd prefer |
Will that work with Freezed? |
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:serverpod/serverpod.dart';
part 'freezedtype.freezed.dart';
part 'freezedtype.g.dart';
@freezed
class FreezedType with _$FreezedType {
const factory FreezedType({
required String firstName,
required String lastName,
required int age,
}) = _FreezedType;
factory FreezedType.fromJson(Map<String, Object?> json,
SerializationManager serializationManager) =>
_$FreezedTypeFromJson(json);
} It does. At least there are no analyzer errors. |
!!THIS IS JUST A DRAFT!! I'm surprised it's that short, but I don't think I missed something. Migrate to serverpod 1.0Serverpod 1.0 is incompatible with previous versions! Protocol specificationTypes in your protocol from other modules must be prefixed with Cache
FutureCallsThe type of the parameter invoke requires must now be set as an generic of class ExampleFutureCall extends FutureCall<Example> {
@override
Future<void> invoke(Session session, Example? object) async {
// Do something interesting in the future here.
}
} DateTimeFrom now on, every DateTime handled by serverpod is converted to UTC. This includes returned DateTimes. EnumsEnums are now serialized and stored in the database as integers. You can migrate your database by running In case the enum detection does not work for your edge case you can add |
I think it's done. I added a small migration guide. But I have no project to test if something else is necessary. |
@vlidholt Just a friendly ping, since I'm not sure if you've seen it. |
@fischerscode These changes are needed for me to be able to merge this pull request. Will you have the bandwidth to fix it in the next few days or should I go ahead and try to implement the fixes? |
Ok, I fixed those things. I changed the syntax for adding extra classes to: extraClasses:
- project:src/custom_classes.dart:CustomClass The deserialization of nullable types still feel a bit like a hack, but I'm going to do some final testing then merge this now. |
This PR reworks the serialization system.
Main changes:
serverpod generate
a deserializer is added to theSerializationManager
. (streamMessages
are still warped. Since there is no type context available.)serverpod:
orprotocol:
ormodule:SERVERPOD_MODULE:
,VALID_DART_IMPORT:
)Advantages:
#309
Pre-launch Checklist
///
), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes