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

152
Visualizações
Angular 7 HTTP put strips out undefined property

I'm trying to send a HTTP PUT request to an API that accepts a JSON object in its body. Everything works fine, except if I want to set a prop of the body to undefined, that prop will be stripped out entirely from the response object (as if I would call the delete operator for that prop). I checked and I can confirm that the given prop is there, with the value of undefined as long as the object is passed to httpClient.put().

Does anybody know why does this happen? Is this an expected behavior for the http client, or there's a bug somewhere?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The behavior you describe it's the expected behavior of HttpClient. Actually, it's the behavior of JSON.stringify() which HttpClient uses behind the scenes.

Unlike JavaScript, JSON doesn't have the concept of undefined. If something is undefined, it's just not defined. It doesn't exist at all. So, when JSON.stringify() gets an object with a property that equals undefined, it omits him.

If you need this property in your request's body, try to change its value to null, empty string, or zero (depending on your server-side).

about 4 years ago · Juan Pablo Isaza Relatório
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