私は以下のジャクソンマッパー機能を有効にする: MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES
Spring application.propertiesでJackson ObjectMapperをカスタマイズする方法は?
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.htmlによると: spring.jackson.mapper.accept_case_insensitive_properties=true
:しかし
@RestController
public class MyServlet {
@RequestMapping("/test")
public void test(@Valid TestReq req) {
}
}
public class TestReq {
@NotBlank
private String name;
}
使用状況を次のように
がapplication.properties
に構成することができ:
localhost:8080/test?name=test //works
localhost:8080/test?Name=test //fails with 'name may not be blank'
したがって、大文字小文字を区別しないプロパティは考慮されません。しかし、なぜ?ところで
:でも、明示的なJackson2ObjectMapperBuilderCustomizer
を使用しては動作しません:
@Bean
public Jackson2ObjectMapperBuilderCustomizer initJackson() {
Jackson2ObjectMapperBuilderCustomizer c = new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
builder.featuresToEnable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
}
};
return c;
}
春ブート-1.5.3.RELEASE
ObjectMapperインスタンスは、JavaクラスファイルまたはSpringコンフィグレーションのどこに作成しますか? – Richard
これは 'spring-boot'または' spring-mvc'によって自動的に作成されるため、初期化時に設定プロパティを使用する必要があります。 – membersound
私はあなたのタグを変更してspring-bootを追加する必要があると思います – Richard