Set response body for derived types
See original GitHub issueOverivew
This is a suggestion, not a bug. I can submit a PR one of these days,
Suggestion
- Change
Body
to internal set/init for StringResponse and similar - Remove parameterized constructor
- Change the if-else chain on
ResponseBuilder:229
from
responseType == typeof(StringResponse)
to
typeof(StringResponse).IsAssignableFrom(responseType)
Version
Targeting 7.x branch
Thoughts
I know it’s not a necessary change, because there are existing workarounds. The one I’m currently using is to derive from ElasticsearchResponseBase
and define my own Property, which is deserialized from ResponseBodyInBytes
in the getter. However, I think It would be better the Body is handled internally, since a child of StringResponse
it’s still a StringResponse
, albeit a more derived one. And if you don’t intend to let people derive from them, they should be defined as sealed IMO.
What do you think?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Derived type's properties missing in JSON response from ...
Here is a derived type that defines a new public property named Value . public class StringResultProperty : IResultProperty { public string ...
Read more >Controller action return types in ASP.NET Core web API
In this code path, the Product object is provided in the response body. A Location response header containing the newly created product's URL...
Read more >Format response data in ASP.NET Core Web API
ASP.NET Core MVC supports formatting response data, using specified formats or in response to a client's request. Format-specific Action Results.
Read more >Inheritance and Polymorphism
Polymorphism. In your API, you can have request and responses that can be described by several alternative schemas. In OpenAPI 3.0, to describe...
Read more >Express 4.x - API Reference
Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. This parser accepts...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the reply. We’d recommend you return
ByteResponse
and do any deserialisation from there. Consumers being able to derive from any of these base or specialised response types is not intended behaviour. I am including this on a worklist we have for the Transport work for v8. I’m going to close this issue as we won’t make this change for7.x
in this responsitory. Thanks for raising this though as it prompted me to revisit this area and will benefit the package going forward.Well, because it seems a good way to centralise the deserialization. I did use StringResponse’s body to start with and deserialized in my service method, but since ElasticsearchLowLevelClient allows for custom responses (i.e. its constrained to an interface), why not make one that handles it instead?