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

307
Visualizações
Autowire json value in springboot from yaml

How to read json as a string from a yaml file in spring boot application ?

I need to get the json as a string / json object.

Application.yml

Shirt:
 rest:
  booking:
   invoiceAddress: {"name":"VIA Pics AB","address1":"VIA Pics AB","address2":"Mejerivägen 3","zipCode":"11743","city":"STOCKHOLM","countryCode":"SE","email":"w.ho@Pics.fr"}

Configuration class

@Configuration
public class ConfigurationServiceClientConfiguration {

    @Value("${Shirt.rest.booking.invoiceAddress}")
    private String invoiceAddress;

    @Bean
    public String getInvoiceAddress(){
        System.out.println(invoiceAddress);
        return this.invoiceAddress;
    }
}

Also tried @JsonProperty but no idea whether my usage was wrong or not !

Note: I am not ready to change the json as a list because more jsons (of invoiceAddress) to come and I will have to make list for each. So it's easy for me if the json can be copied as it is to the yaml file.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

If you want as a plan string you should add this value between single quote 'your value.' in your yml file

Shirt:
 rest:
  booking:
   invoiceAddress: '{"name":"VIA Pics AB","address1":"VIA Pics AB","address2":"Mejerivägen 3","zipCode":"11743","city":"STOCKHOLM","countryCode":"SE","email":"w.ho@Pics.fr"}'
about 4 years ago · Santiago Trujillo Relatório

0

Try modifying your yml file as below:

Shirt.rest.booking:
   invoiceAddress: "\"name\":\"VIA Pics AB\",\"address1\":\"VIA Pics AB\",\"address2\":\"Mejerivägen 3\",\"zipCode\":\"11743\",\"city\":\"STOCKHOLM\",\"countryCode\":\"SE\",\"email\":\"w.ho@Pics.fr\""
about 4 years ago · Santiago Trujillo Relatório

0

Single quotes escapes all the special characters in the values of YAML properties. Just try adding to the string into single quotes 'PropertiesValue'.

E.g :

invoiceAddress: '{"name":"VIA Pics AB","address1":"VIA Pics AB","address2":"Mejerivägen 3","zipCode":"11743","city":"STOCKHOLM","countryCode":"SE","email":"w.ho@Pics.fr"}'
about 4 years ago · Santiago Trujillo 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