use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project JavaForFun by gumartinm.
the class CarControllerIntegrationTest method setup.
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(MapperFeature.DEFAULT_VIEW_INCLUSION).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).enable(SerializationFeature.INDENT_OUTPUT).registerModule(new JavaTimeModule());
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project tutorials by eugenp.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project tutorials by eugenp.
the class TestUtil method convertObjectToJsonBytes.
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project batfish by batfish.
the class BatfishObjectMapper method baseMapper.
/**
* Configures all the default options for a Batfish {@link ObjectMapper}.
*/
private static ObjectMapper baseMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
// Next two lines make Instant class serialize as an RFC-3339 timestamp
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// This line makes Java 8's Optional type serialize
mapper.registerModule(new Jdk8Module());
// See https://groups.google.com/forum/#!topic/jackson-user/WfZzlt5C2Ww
// This fixes issues in which non-empty maps with keys with empty values would get omitted
// entirely. See also https://github.com/batfish/batfish/issues/256
mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(Include.NON_EMPTY, Include.ALWAYS));
// This line makes Guava collections work with jackson
mapper.registerModule(new GuavaModule());
return mapper;
}
use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project core-ng-project by neowu.
the class JSONMapper method createObjectMapper.
private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new AfterburnerModule());
mapper.setDateFormat(new StdDateFormat());
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
mapper.setAnnotationIntrospector(new JSONAnnotationIntrospector());
return mapper;
}
Aggregations