Commit 1e91098d authored by Matija Obreza's avatar Matija Obreza
Browse files

API: Fix encoding of dates in JSON

parent b3e2b588
......@@ -117,6 +117,12 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
......
......@@ -38,6 +38,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
/**
* Spring MVC
......@@ -75,7 +77,10 @@ public class WebConfiguration implements WebMvcConfigurer {
@Bean
public ObjectMapper objectMapper() {
final ObjectMapper mapper = new ObjectMapper();
var javaTimeModule = new JavaTimeModule();
mapper.registerModule(javaTimeModule);
// serialization
mapper.disable(SerializationFeature.EAGER_SERIALIZER_FETCH);
// deserialization
......@@ -87,6 +92,10 @@ public class WebConfiguration implements WebMvcConfigurer {
// explicit json views: every fields needs to be annotated, therefore enabled
mapper.enable(MapperFeature.DEFAULT_VIEW_INCLUSION);
// JSON Dates
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
return mapper;
}
......
......@@ -16,21 +16,9 @@
package org.genesys.amphibian.test.api;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.oneOf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
......@@ -202,6 +190,23 @@ public class PreviewApiTest extends AbstractApiTest {
assertThat(sheet0.rowCount, is(2));
// System.err.println(new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(sheet0));
assertThat(sheet0.descriptors.get(0).columnName, is("INSTCODE"));
/*@formatter:off*/
mockMvc
.perform(
post(PreviewApi.CONTROLLER_URL.concat("/{uuid}/{sheet}/{startRow}"), uuid.toString(), 0, 0)
.characterEncoding("UTF8")
.contentType(MediaType.APPLICATION_JSON)
)
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.[1].C0", is("SYR002")))
.andExpect(jsonPath("$.[1].C1", is("IG 137552")))
.andExpect(jsonPath("$.[1].C2", is("Lens")))
.andExpect(jsonPath("$.[1].C3").isString()) // Not encoded as number
.andExpect(jsonPath("$.[1].C3", not(emptyString())))
;
/*@formatter:on*/
}
private void setCellValue(Cell cell, Object obj, CellStyle dateStyle) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment