Я использую версию с весенней загрузкой 2.25. Моя проблема в том, что свойства бина не работают, если я использую @XmlElement
Я добавил все банки Джексона и также настроил картограф Джексона.
Ниже мой pom. xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
//Configuration Class
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
return (mapperBuilder) -> mapperBuilder.modulesToInstall(new JaxbAnnotationModule());
}
Test. java
@XmlRootElement
puiblic class Test {
@XmlElement(name = "id")
private String identifier;
//Getter and Setter
}
@RestController
@RequestMapping("/api")
public class TestResource {
@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public String printTest(@RequestBody Test test) {
LOGGER.debug(" Test {}",test.getId());
return "hello";
}
}
Когда я нажимаю на запрос с
{"id" : "1"}
Я получаю исключение нулевого указателя.
Когда я нажимаю на запрос с
{"identifier" : "1"}
, я получаю ответ
привет.
Почему аннотации @XmlElement
не работают в моем Проект весенней загрузки.
Любая помощь будет принята с благодарностью !!!