Example usage for org.springframework.validation DataBinder convertIfNecessary

List of usage examples for org.springframework.validation DataBinder convertIfNecessary

Introduction

In this page you can find the example usage for org.springframework.validation DataBinder convertIfNecessary.

Prototype

@Override
    @Nullable
    public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType)
            throws TypeMismatchException 

Source Link

Usage

From source file:org.springframework.springfaces.mvc.bind.ReverseDataBinderTest.java

private void doTestReverseConvert(String value, Object expected) throws Exception {
    DataBinder dataBinder = new DataBinder(null);
    initBinder(dataBinder);//  w  ww .j a v a2s. co m
    Object converted = (value == null ? null : dataBinder.convertIfNecessary(value, expected.getClass()));
    assertThat(converted, is(equalTo(expected)));
    ReverseDataBinder reverseDataBinder = new ReverseDataBinder(dataBinder);
    String reversed = reverseDataBinder.reverseConvert(converted);
    assertThat(reversed, is(equalTo(value)));
}