Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
Why is an Enum represented in two different ways in an API request?

I guess that will be a duplicated question because it's something quite basic, but after some search I was not able to find the answer.

I have a .net462 application. I have the following enum:

 public enum Test
 {
     Foo,
     Bar,
 }

and the following endpoint in one controller:

 [HttpGet]
 [Route("myTest")]
 public IEnumerable<Test> GetMyFooTest()
 {
     return new List<Test> { Test.Bar, Test.Foo };
 }

Now, if I use chrome to retrieve data from the endpoint, I get: Browser screenshot

Here the Enums appear in its string form.

However, when I call this endpoint from the front end (JS, jQuery), or if I call it using Postman, I get: Postman screenshot

No matter if I visualise it with JSON, XML or any option: options

Here I get the numerical values of the Enums.

Why this difference? Is there a way to get the string values in the front end? (of course I have the option to change the controller to return a IEnumerable<string> and use a ToString() on the c# side, but that would be quite ugly...).

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda