Skip to content

Commit 53c0f39

Browse files
committed
[Fix #840] Allow overriding of default object mapper
By default, the internal object mapper will call findAndRegisterModules. If this is not the desired behaviour, implementors might replace it by a custom object mapper of their choice Signed-off-by: fjtirado <[email protected]>
1 parent 666cdb3 commit 53c0f39

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

impl/jackson/src/main/java/io/serverlessworkflow/impl/jackson/JsonUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.HashMap;
4646
import java.util.Map;
4747
import java.util.Optional;
48+
import java.util.ServiceLoader;
4849
import java.util.Set;
4950
import java.util.function.BiConsumer;
5051
import java.util.function.BinaryOperator;
@@ -54,7 +55,11 @@
5455

5556
public class JsonUtils {
5657

57-
private static ObjectMapper mapper = new ObjectMapper();
58+
private static ObjectMapper mapper =
59+
ServiceLoader.load(ObjectMapperFactory.class)
60+
.findFirst()
61+
.orElseGet(() -> () -> new ObjectMapper().findAndRegisterModules())
62+
.get();
5863

5964
public static ObjectMapper mapper() {
6065
return mapper;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.jackson;
17+
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import java.util.function.Supplier;
20+
21+
public interface ObjectMapperFactory extends Supplier<ObjectMapper> {}

0 commit comments

Comments
 (0)