question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set response body for derived types

See original GitHub issue

Overivew

This is a suggestion, not a bug. I can submit a PR one of these days,

Suggestion

  1. Change Body to internal set/init for StringResponse and similar
  2. Remove parameterized constructor
  3. 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stevejgordoncommented, Mar 24, 2022

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 for 7.x in this responsitory. Thanks for raising this though as it prompted me to revisit this area and will benefit the package going forward.

0reactions
achobanovcommented, Mar 21, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found