Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!