Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
9018c33d
Commit
9018c33d
authored
Dec 22, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix possible concurrent issues
parent
67b39843
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
commons/common-util/src/main/java/com/schbrain/common/util/JacksonUtils.java
.../src/main/java/com/schbrain/common/util/JacksonUtils.java
+13
-10
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/JacksonUtils.java
View file @
9018c33d
package
com.schbrain.common.util
;
package
com.schbrain.common.util
;
import
cn.hutool.core.lang.Singleton
;
import
cn.hutool.extra.spring.SpringUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.*
;
...
@@ -27,17 +28,19 @@ public class JacksonUtils {
...
@@ -27,17 +28,19 @@ public class JacksonUtils {
private
static
ObjectMapper
PRETTY_OBJECT_MAPPER
;
private
static
ObjectMapper
PRETTY_OBJECT_MAPPER
;
public
static
ObjectMapper
getObjectMapper
()
{
public
static
ObjectMapper
getObjectMapper
()
{
if
(
OBJECT_MAPPER
==
null
)
{
return
Singleton
.
get
(
JacksonUtils
.
class
.
getName
(),
()
->
{
// Delay to get ObjectMapper from spring container to keep the same behavior with application
if
(
OBJECT_MAPPER
==
null
)
{
try
{
// Delay to get ObjectMapper from spring container to keep the same behavior with application
OBJECT_MAPPER
=
SpringUtil
.
getBean
(
ObjectMapper
.
class
).
copy
();
try
{
}
catch
(
Exception
e
)
{
OBJECT_MAPPER
=
SpringUtil
.
getBean
(
ObjectMapper
.
class
).
copy
();
log
.
warn
(
"Could not get ObjectMapper from Spring Container, return new instance for use"
);
}
catch
(
Exception
e
)
{
OBJECT_MAPPER
=
new
ObjectMapper
();
log
.
warn
(
"Could not get ObjectMapper from Spring Container, return new instance for use"
);
OBJECT_MAPPER
=
new
ObjectMapper
();
}
OBJECT_MAPPER
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
}
}
OBJECT_MAPPER
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
return
OBJECT_MAPPER
;
}
});
return
OBJECT_MAPPER
;
}
}
public
static
ObjectMapper
getPrettyObjectMapper
()
{
public
static
ObjectMapper
getPrettyObjectMapper
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment