use of com.serotonin.m2m2.web.mvc.rest.v1.mapping.JScienceModule in project ma-core-public by infiniteautomation.
the class MangoRestSpringConfiguration method createNewObjectMapper.
/**
* Create an instance of the Object Mapper.
* Used locally when starting Spring but may also be used for testing.
*
* Note: This is NOT the same Object Mapper instance used within a running Mango.
* XXX J.W. Seems to be used inside the REST controller to me?
*
* @return
*/
public static ObjectMapper createNewObjectMapper() {
// For raw Jackson
ObjectMapper objectMapper = new ObjectMapper();
if (Common.envProps.getBoolean("rest.indentJSON", false))
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
// JScience
JScienceModule jScienceModule = new JScienceModule();
objectMapper.registerModule(jScienceModule);
// Mango Core JSON Modules
MangoCoreModule mangoCore = new MangoCoreModule();
objectMapper.registerModule(mangoCore);
MangoRestV2JacksonModule mangoCoreV2 = new MangoRestV2JacksonModule();
objectMapper.registerModule(mangoCoreV2);
// Setup Module Defined JSON Modules
List<JacksonModuleDefinition> defs = ModuleRegistry.getDefinitions(JacksonModuleDefinition.class);
for (JacksonModuleDefinition def : defs) {
if (def.getSourceMapperType() == JacksonModuleDefinition.ObjectMapperSource.REST)
objectMapper.registerModule(def.getJacksonModule());
}
// Always output dates in ISO 8601
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
objectMapper.setDateFormat(dateFormat);
objectMapper.registerModule(new JavaTimeModule());
// Set to system tz
objectMapper.setTimeZone(TimeZone.getDefault());
// This will allow messy JSON to be imported even if all the properties in it are part of the POJOs
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
Aggregations