Skip to content

Use registred CustomSerializer for Criteria-Objects#4866

Open
jensbrand wants to merge 3 commits into
MarimerLLC:mainfrom
jensbrand:dev/4865-customserializer-for-criterias
Open

Use registred CustomSerializer for Criteria-Objects#4866
jensbrand wants to merge 3 commits into
MarimerLLC:mainfrom
jensbrand:dev/4865-customserializer-for-criterias

Conversation

@jensbrand

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Criteria objects not inheriting from IMobileObject bypass registered custom serializers, causing serialization errors.
  • Solution: Refactored PrimitiveCriteria into a ReadOnlyBase and updated DataPortalProxy to instantiate it via the data portal.
  • Result: Criteria objects now serialize like standard properties and correctly utilize custom serializers.

Related Issue

Fixes #4865 (Custom Serializer for Criteria-Objects)

jensbrand added 2 commits June 3, 2026 15:34
…ated `DataPortalProxy` to use `IDataPortal<PrimitiveCriteria>` for criteria creation.

@StefanOssendorf StefanOssendorf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Thank you for your contribution.

However I think this is the wrong approach to solve this issue. The PrimitiveCriteria was meant to deal with the .net primitives (int, string, DateTime, ...) and not with custom serializers.

I think the correct way would be something like adding a way to ISerializationFormatter to ask if it can check a particular type.
If yes: Skip PrimitiveCriteria
If no: Use PrimitiveCriteria

But this is something more fundamental where I'd like to get @rockfordlhotka opinion this. Your way works, maybe as a temporary implementation, but it should be implemented in another way for the future.

@rockfordlhotka

Copy link
Copy Markdown
Member

Looking at the changes, this might be the simplest overall solution. There's no real downside (I don't think) to having it subclass ReadOnlyBase instead of directly implementing IMobileObject.

The drawback is that we're now involving DI to create instances of something that used to be cheap and trivial, but it is probably not going to be a noticeable perf issue.

On the other hand, what @StefanOssendorf says could be valid - other serializers (like the super-fast one from @JasonBock) could, in theory, support serialization of types in ways different from MobileFormatter - with support for different types entirely. For example, I don't think Jason's serializer relies on IMobileObject at all.

@JasonBock

Copy link
Copy Markdown
Contributor

The only thing my serializer does with IMobileObject is to check if an object in the graph doesn't implement IGeneratorSerializable (which is what the source generator does for you). This is for the (hopefully rare) case where a type definition couldn't be updated and we have to fall back to MobileFormatter.

Also, my SG allows a user to register custom serialization implementations for types if needed.

@jensbrand

Copy link
Copy Markdown
Contributor Author

Even with @JasonBock's serializer, serializing Criteria objects still doesn't work, even after registering a CustomSerializer for it. I suspect the fallback to IMobileFormatter that Jason mentioned is the culprit here, since PrimitiveCriteria derives from it.

@JasonBock

Copy link
Copy Markdown
Contributor

@jensbrand probably because I don't support CriteriaBase right now - https://github.com/JasonBock/CslaGeneratorSerialization/blob/main/src/CslaGeneratorSerialization.Analysis/Builders/GeneratorSerializationBuilder.cs#L65-L88. Not that I couldn't, I just need to add that support in - I added an issue to address this: JasonBock/CslaGeneratorSerialization#46

@JasonBock

Copy link
Copy Markdown
Contributor

@jensbrand BTW can you submit a bug report to my serializer with your PrimitiveCriteria issue? My serializer should work with any type that derives from IMobileObject, but there may be something subtle that I'm missing.

@jensbrand

Copy link
Copy Markdown
Contributor Author

@jensbrand BTW can you submit a bug report to my serializer with your PrimitiveCriteria issue? My serializer should work with any type that derives from IMobileObject, but there may be something subtle that I'm missing.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Serializer for Criteria-Objects

4 participants