Example usage for org.springframework.format.datetime DateFormatter print

List of usage examples for org.springframework.format.datetime DateFormatter print

Introduction

In this page you can find the example usage for org.springframework.format.datetime DateFormatter print.

Prototype

@Override
    public String print(Date date, Locale locale) 

Source Link

Usage

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvConfigurationIntegrationTests.java

/**
 * @see DATAREST-336//from   w  w  w  . j a va2s  . c  o  m
 */
@Test
public void objectMapperRendersDatesInIsoByDefault() throws Exception {

    Sample sample = new Sample();
    sample.date = new Date();

    ObjectMapper mapper = context.getBean("objectMapper", ObjectMapper.class);

    DateFormatter formatter = new DateFormatter();
    formatter.setIso(ISO.DATE_TIME);

    Object result = JsonPath.read(mapper.writeValueAsString(sample), "$.date");
    assertThat(result, is(instanceOf(String.class)));
    assertThat(result, is((Object) formatter.print(sample.date, Locale.US)));
}