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

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

Introduction

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

Prototype

public void setIso(ISO iso) 

Source Link

Document

Set the ISO format used for this date.

Usage

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

/**
 * @see DATAREST-336/*from   w  ww . j a  v a2 s.  co 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)));
}