The DTO converter factory claims it can convert the implementation type, but trying to do so directly will fail on STJ's level.
(Seems like converters returned by factories are expected to exactly match the type provided.)
By "directly", I mean situations like JsonSerializer.Deserialize<TImplementation>(...) or simply specifying the implementation type instead of the interface in a DTO otherwise.
This is definitely not the intended pattern, but it used to work and the factory still claims it's supported through its CanConvert method.
That said, this PR makes the DTOConverter return a converter for the correct type and adds tests to assert doing the above works.
(Regarding the change in ExpressionFactoryUtilities, the previous check used to fail if typeof(T) == DeclaringType.)
Turns out I introduced a subtle bug in https://github.com/Remora/Remora.Rest/pull/13.
The DTO converter factory claims it can convert the implementation type, but trying to do so directly will fail on STJ's level. (Seems like converters returned by factories are expected to exactly match the type provided.)
By "directly", I mean situations like
JsonSerializer.Deserialize<TImplementation>(...)
or simply specifying the implementation type instead of the interface in a DTO otherwise.This is definitely not the intended pattern, but it used to work and the factory still claims it's supported through its
CanConvert
method.That said, this PR makes the DTOConverter return a converter for the correct type and adds tests to assert doing the above works.
(Regarding the change in
ExpressionFactoryUtilities
, the previous check used to fail iftypeof(T) == DeclaringType
.)