-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Customize JacksonJsonProvider (indent)
- Loading branch information
1 parent
ec2f013
commit 10c40bb
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright DB InfraGO AG and contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.db.capella.api; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
import com.fasterxml.jackson.datatype.jsr310.*; | ||
|
||
import com.fasterxml.jackson.jakarta.rs.json.JacksonXmlBindJsonProvider; | ||
|
||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
@Produces({MediaType.APPLICATION_JSON}) | ||
public class JacksonJsonProvider extends JacksonXmlBindJsonProvider { | ||
|
||
public JacksonJsonProvider() { | ||
|
||
ObjectMapper objectMapper = new ObjectMapper() | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
.enable(SerializationFeature.INDENT_OUTPUT) | ||
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS) | ||
.registerModule(new JavaTimeModule()) | ||
.setDateFormat(new RFC3339DateFormat()); | ||
|
||
setMapper(objectMapper); | ||
} | ||
} |