Java Code Examples for com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS

The following examples show how to use com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonUtil.java    From blade-tool with GNU Lesser General Public License v3.0 7 votes vote down vote up
public JacksonObjectMapper() {
	super();
	//设置地点为中国
	super.setLocale(CHINA);
	//去掉默认的时间戳格式
	super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
	//设置为中国上海时区
	super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
	//序列化时,日期的统一格式
	super.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA));
	//序列化处理
	super.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
	super.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true);
	super.findAndRegisterModules();
	//失败处理
	super.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	//单引号处理
	super.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
	//反序列化时,属性不存在的兼容处理s
	super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
	//日期格式化
	super.registerModule(new BladeJavaTimeModule());
	super.findAndRegisterModules();
}
 
Example 2
Source File: MCRRestObjects.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON + ";charset=UTF-8" })
@MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.HOURS),
    sMaxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.HOURS))
@Operation(
    summary = "Lists all objects in this repository",
    responses = @ApiResponse(
        content = @Content(array = @ArraySchema(schema = @Schema(implementation = MCRObjectIDDate.class)))),
    tags = MCRRestUtils.TAG_MYCORE_OBJECT)
@XmlElementWrapper(name = "mycoreobjects")
@JacksonFeatures(serializationDisable = { SerializationFeature.WRITE_DATES_AS_TIMESTAMPS })
public Response listObjects() throws IOException {
    Date lastModified = new Date(MCRXMLMetadataManager.instance().getLastModified());
    Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, lastModified);
    if (cachedResponse.isPresent()) {
        return cachedResponse.get();
    }
    List<MCRRestObjectIDDate> idDates = MCRXMLMetadataManager.instance().listObjectDates().stream()
        .filter(oid -> !oid.getId().contains("_derivate_"))
        .map(x -> new MCRRestObjectIDDate(x))
        .collect(Collectors.toList());
    return Response.ok(new GenericEntity<List<MCRRestObjectIDDate>>(idDates) {
    })
        .lastModified(lastModified)
        .build();
}
 
Example 3
Source File: MCRRestObjects.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON + ";charset=UTF-8" })
@MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS),
    sMaxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS))
@Path("/{" + PARAM_MCRID + "}/versions")
@Operation(
    summary = "Returns MCRObject with the given " + PARAM_MCRID + ".",
    responses = @ApiResponse(content = @Content(
        array = @ArraySchema(uniqueItems = true, schema = @Schema(implementation = MCRMetadataVersion.class)))),
    tags = MCRRestUtils.TAG_MYCORE_OBJECT)
@JacksonFeatures(serializationDisable = { SerializationFeature.WRITE_DATES_AS_TIMESTAMPS })
@XmlElementWrapper(name = "versions")
public Response getObjectVersions(@Parameter(example = "mir_mods_00004711") @PathParam(PARAM_MCRID) MCRObjectID id)
    throws IOException {
    long modified = MCRXMLMetadataManager.instance().getLastModified(id);
    if (modified < 0) {
        throw MCRErrorResponse.fromStatus(Response.Status.NOT_FOUND.getStatusCode())
            .withErrorCode(MCRErrorCodeConstants.MCROBJECT_NOT_FOUND)
            .withMessage("MCRObject " + id + " not found")
            .toException();
    }
    Date lastModified = new Date(modified);
    Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, lastModified);
    if (cachedResponse.isPresent()) {
        return cachedResponse.get();
    }
    List<MCRMetadataVersion> versions = MCRXMLMetadataManager.instance().getVersionedMetaData(id)
        .listVersions();
    return Response.ok()
        .entity(new GenericEntity<>(versions, TypeUtils.parameterize(List.class, MCRMetadataVersion.class)))
        .lastModified(lastModified)
        .build();
}