Syed :
Here is my Yaml properties file
bb:
employees:
-
employee1:
name: Syed
locations:
- HYD
- MAA
-
employee2:
name: Adhil
locations:
- BOM
- DEL
I want to convert the object into my POJO in my applicaiton. However I'm not able to do it, it always returns null.
Is there anything which I'm missing?
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "bb")
public class EmpConfig {
EmployeeDetails employees;
}
EmployeeDetails Class
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Configuration
public class EmployeeDetails {
List<Map<String, List<String>>> details;
}
Saphyra :
It worked me this way:
The YAML (called application.yaml) (dashes removed before the employeeIds (employee1, employee2))
bb:
employees:
employee1:
name: Syed
locations:
- HYD
- MAA
employee2:
name: Adhil
locations:
- BOM
- DEL
Config class:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "bb")
public class EmpConfig {
private Map<String, EmployeeDetails> employees;
}
EmployeeDetails:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class EmployeeDetails {
private String name;
private List<String> locations;
}
So basically you have problems with the syntax, and the data types, so Spring cannot parse the configuration file.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=371554&siteId=1