Search in sources :

Example 1 with IgnoreErrorsBindHandler

use of org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler in project incubator-dubbo-spring-boot-project by apache.

the class BinderDubboConfigBinder method getBindHandler.

private BindHandler getBindHandler(boolean ignoreUnknownFields, boolean ignoreInvalidFields) {
    BindHandler handler = BindHandler.DEFAULT;
    if (ignoreInvalidFields) {
        handler = new IgnoreErrorsBindHandler(handler);
    }
    if (!ignoreUnknownFields) {
        UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
        handler = new NoUnboundElementsBindHandler(handler, filter);
    }
    return handler;
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) UnboundElementsSourceFilter(org.springframework.boot.context.properties.source.UnboundElementsSourceFilter) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler)

Example 2 with IgnoreErrorsBindHandler

use of org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler in project spring-boot by spring-projects.

the class ConfigurationPropertiesBinder method getBindHandler.

private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperties annotation) {
    List<Validator> validators = getValidators(target);
    BindHandler handler = getHandler();
    handler = new ConfigurationPropertiesBindHandler(handler);
    if (annotation.ignoreInvalidFields()) {
        handler = new IgnoreErrorsBindHandler(handler);
    }
    if (!annotation.ignoreUnknownFields()) {
        UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
        handler = new NoUnboundElementsBindHandler(handler, filter);
    }
    if (!validators.isEmpty()) {
        handler = new ValidationBindHandler(handler, validators.toArray(new Validator[0]));
    }
    for (ConfigurationPropertiesBindHandlerAdvisor advisor : getBindHandlerAdvisors()) {
        handler = advisor.apply(handler);
    }
    return handler;
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) UnboundElementsSourceFilter(org.springframework.boot.context.properties.source.UnboundElementsSourceFilter) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BoundPropertiesTrackingBindHandler(org.springframework.boot.context.properties.bind.BoundPropertiesTrackingBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) IgnoreTopLevelConverterNotFoundBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler) ValidationBindHandler(org.springframework.boot.context.properties.bind.validation.ValidationBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) AbstractBindHandler(org.springframework.boot.context.properties.bind.AbstractBindHandler) Validator(org.springframework.validation.Validator) ValidationBindHandler(org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)

Example 3 with IgnoreErrorsBindHandler

use of org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler in project dubbo by alibaba.

the class BinderDubboConfigBinder method getBindHandler.

private BindHandler getBindHandler(boolean ignoreUnknownFields, boolean ignoreInvalidFields) {
    BindHandler handler = BindHandler.DEFAULT;
    if (ignoreInvalidFields) {
        handler = new IgnoreErrorsBindHandler(handler);
    }
    if (!ignoreUnknownFields) {
        UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
        handler = new NoUnboundElementsBindHandler(handler, filter);
    }
    return handler;
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) UnboundElementsSourceFilter(org.springframework.boot.context.properties.source.UnboundElementsSourceFilter) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler)

Example 4 with IgnoreErrorsBindHandler

use of org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler in project spring-boot by spring-projects.

the class JavaBeanBinderTests method bindToClassWhenPropertyCannotBeConvertedAndIgnoreErrorsShouldNotSetValue.

@Test
void bindToClassWhenPropertyCannotBeConvertedAndIgnoreErrorsShouldNotSetValue() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.int-value", "12");
    source.put("foo.long-value", "bang");
    source.put("foo.string-value", "foo");
    source.put("foo.enum-value", "foo-bar");
    this.sources.add(source);
    IgnoreErrorsBindHandler handler = new IgnoreErrorsBindHandler();
    ExampleValueBean bean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class), handler).get();
    assertThat(bean.getIntValue()).isEqualTo(12);
    assertThat(bean.getLongValue()).isEqualTo(0);
    assertThat(bean.getStringValue()).isEqualTo("foo");
    assertThat(bean.getEnumValue()).isEqualTo(ExampleEnum.FOO_BAR);
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

IgnoreErrorsBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler)4 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)3 NoUnboundElementsBindHandler (org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler)3 UnboundElementsSourceFilter (org.springframework.boot.context.properties.source.UnboundElementsSourceFilter)3 Test (org.junit.jupiter.api.Test)1 AbstractBindHandler (org.springframework.boot.context.properties.bind.AbstractBindHandler)1 BoundPropertiesTrackingBindHandler (org.springframework.boot.context.properties.bind.BoundPropertiesTrackingBindHandler)1 IgnoreTopLevelConverterNotFoundBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler)1 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)1 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)1 Validator (org.springframework.validation.Validator)1