Skip to content

Commit adda608

Browse files
author
zihluwang
committed
feat: object mapper holder
1 parent c37ffdb commit adda608

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
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+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.jwt.holder;
19+
20+
import com.fasterxml.jackson.databind.MapperFeature;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.json.JsonMapper;
23+
24+
import java.util.Objects;
25+
26+
public class ObjectMapperHolder {
27+
28+
private static ObjectMapperHolder HOLDER;
29+
30+
private final ObjectMapper objectMapper;
31+
32+
/**
33+
* Private constructor to prevent instantiation of this utility class.
34+
*/
35+
private ObjectMapperHolder() {
36+
this.objectMapper = JsonMapper.builder()
37+
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
38+
.build();
39+
}
40+
41+
/**
42+
* Get singleton instance.
43+
*
44+
* @return the {@code ObjectMapperHolder} instance
45+
*/
46+
public static ObjectMapperHolder getInstance() {
47+
if (Objects.isNull(HOLDER)) {
48+
synchronized (ObjectMapperHolder.class) {
49+
if (Objects.isNull(HOLDER)) {
50+
HOLDER = new ObjectMapperHolder();
51+
}
52+
}
53+
}
54+
return HOLDER;
55+
}
56+
57+
/**
58+
* Get Object
59+
*
60+
* @return
61+
*/
62+
public ObjectMapper getObjectMapper() {
63+
return objectMapper;
64+
}
65+
}

0 commit comments

Comments
 (0)