1

I have the following call, which works as supposed to.

[HttpGet("translation")]
public ActionResult Translations(string id)
{
  CultureInfo culture = new CultureInfo(id);
  return Translation
    .GetTranslationByCulture(culture);
}

I wanted to try passing a full cultural info object to avoid the conversion in the API, like this.

[HttpGet("translation2")]
public ActionResult Translations2(CultureInfo culture)
{
  return Translation
    .GetTranslationByCulture(culture);
}

It kind of works but I'm not sure what string passed from Angular (or in Swagger, for that matter), that would be a proper serialization of the CultureInfo instance. I tried backward enginering it by returning an instance from my API but got an error 500 due to exceeded limit of circular references in the returned object (as the JSON serialization supports depth of 32 at best).

What do I send in to the parsed as an instance of a culture?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • 1
    Since `CultureInfo` has no parameterless constructor you need a custom serializer for that. And for that I don't know what you going to accomplish that. I would suggest sticking with the 1. solution. [custom serializer](https://stackoverflow.com/questions/23017716/json-net-how-to-deserialize-without-using-the-default-constructor) – Eldar Dec 14 '19 at 20:13
  • maybe just send parameters for `CultureInfo` and instantiate it with parameters? – StepUp Dec 14 '19 at 20:16
  • @StepUp You mean the way I'm showing in my question? – Konrad Viltersten Dec 14 '19 at 22:57
  • @Eldar You're saying *KISS*, right? – Konrad Viltersten Dec 14 '19 at 22:57
  • @KonradViltersten yeah, like you do. Maybe just send more parameters if you want. – StepUp Dec 15 '19 at 09:27
  • 1
    @KonradViltersten KISS and bunch of other things. In general if you are doing something hard to implement you need to be accomplishing something better. Either provide a better api for the rest of the team which is easy to read and implement or make it restrictive to stick with business rules or it should handle some security layer etc.. I mean it should worth for the pain. – Eldar Dec 16 '19 at 07:55

0 Answers0