Currently when you return a non-response object from a controller action, it is JSON serialized before being returned to the client. However, if the returned object is not a primitive type, and does not include JSON::Serializable or ASR::Serializable everything works the same, but the response body returned to the client is null. This is because the serializer component returns nil if it runs into something it is unable to serialize; which is a bit unexpected and a bit hard to debug if you do not know where to look.
Ideally this could be a compile time error, however the problem is that because of the https://athenaframework.org/Framework/View/FormatHandlerInterface/ feature, just because an object does not include those two types, doesn't necessarily mean the response body will be nil. It could be handled by a diff format, or someone could override the json format.
I'm thinking what we could do is if the data we want to serialize is not nil, the return type of the method is not Nil, and the serialize returns nil: Raise a runtime exception calling this out.
We could scope this to debug mode, but prob would be safe to have in both.
Currently when you return a non-response object from a controller action, it is JSON serialized before being returned to the client. However, if the returned object is not a primitive type, and does not include
JSON::Serializable
orASR::Serializable
everything works the same, but the response body returned to the client isnull
. This is because the serializer component returnsnil
if it runs into something it is unable to serialize; which is a bit unexpected and a bit hard to debug if you do not know where to look.Ideally this could be a compile time error, however the problem is that because of the https://athenaframework.org/Framework/View/FormatHandlerInterface/ feature, just because an object does not include those two types, doesn't necessarily mean the response body will be
nil
. It could be handled by a diff format, or someone could override thejson
format.I'm thinking what we could do is if the data we want to serialize is not
nil
, the return type of the method is notNil
, and the serialize returnsnil
: Raise a runtime exception calling this out.We could scope this to debug mode, but prob would be safe to have in both.