Skip to content

Commit f2acc4c

Browse files
committed
[Fix #840] Alternative implementation
1 parent 666cdb3 commit f2acc4c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
public class JsonUtils {
5656

57-
private static ObjectMapper mapper = new ObjectMapper();
57+
private static ObjectMapper mapper = ObjectMapperFactoryProvider.instance().get().get();
5858

5959
public static ObjectMapper mapper() {
6060
return mapper;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.ServiceLoader;
20+
import java.util.function.Supplier;
21+
22+
public class ObjectMapperFactoryProvider implements Supplier<ObjectMapperFactory> {
23+
24+
private ObjectMapperFactory objectMapperFactory;
25+
26+
private ObjectMapperFactoryProvider() {}
27+
28+
public void setFactory(ObjectMapperFactory objectMapperFactory) {
29+
this.objectMapperFactory = objectMapperFactory;
30+
}
31+
32+
private static ObjectMapperFactoryProvider instance = new ObjectMapperFactoryProvider();
33+
34+
public static ObjectMapperFactoryProvider instance() {
35+
return instance;
36+
}
37+
38+
@Override
39+
public ObjectMapperFactory get() {
40+
return objectMapperFactory != null
41+
? objectMapperFactory
42+
: ServiceLoader.load(ObjectMapperFactory.class)
43+
.findFirst()
44+
.orElseGet(() -> () -> new ObjectMapper().findAndRegisterModules());
45+
}
46+
}

0 commit comments

Comments
 (0)