Dmaap client
[transportpce.git] / dmaap-client / src / main / java / org / opendaylight / transportpce / dmaap / client / resource / config / JsonConfigurator.java
diff --git a/dmaap-client/src/main/java/org/opendaylight/transportpce/dmaap/client/resource/config/JsonConfigurator.java b/dmaap-client/src/main/java/org/opendaylight/transportpce/dmaap/client/resource/config/JsonConfigurator.java
new file mode 100644 (file)
index 0000000..62676c0
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import javax.ws.rs.ext.ContextResolver;
+
+public class JsonConfigurator implements ContextResolver<ObjectMapper> {
+
+    private final ObjectMapper mapper;
+
+    public JsonConfigurator() {
+        mapper = new ObjectMapper();
+        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+        mapper.enable(SerializationFeature.INDENT_OUTPUT);
+        mapper.registerModule(new JavaTimeModule());
+        mapper.registerModule(new PublishNotificationServiceModule());
+    }
+
+    @Override
+    public ObjectMapper getContext(Class<?> type) {
+        return mapper;
+    }
+
+}