Skip to content

Commit

Permalink
feat: Customize JacksonJsonProvider (indent)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamilraichouni committed Oct 30, 2024
1 parent ec2f013 commit 10c40bb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions rest-api/src/com/db/capella/api/JacksonJsonProvider.java
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);
}
}

0 comments on commit 10c40bb

Please sign in to comment.