Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
fc630c5e
Commit
fc630c5e
authored
Jul 16, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加JacksonSerializer
parent
75c6663b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
+2
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/serializer/JacksonSerializer.java
+69
-0
No files found.
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
View file @
fc630c5e
...
...
@@ -24,6 +24,7 @@ public class PluginConstant {
public
static
final
String
RULE
=
"rule"
;
public
static
final
String
REACH_MAX_LIMITED_COUNT
=
"reach max limited count"
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
public
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
public
static
final
String
SEPARATE
=
";"
;
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/serializer/JacksonSerializer.java
0 → 100644
View file @
fc630c5e
package
com
.
nepxion
.
discovery
.
plugin
.
framework
.
serializer
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.text.SimpleDateFormat
;
import
org.apache.commons.lang3.StringUtils
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
public
class
JacksonSerializer
{
private
ObjectMapper
objectMapper
;
public
JacksonSerializer
()
{
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setDateFormat
(
new
SimpleDateFormat
(
PluginConstant
.
DATE_FORMAT
));
}
public
<
T
>
String
toJson
(
T
object
)
{
if
(
object
==
null
)
{
throw
new
IllegalArgumentException
(
"Object is null"
);
}
try
{
return
objectMapper
.
writeValueAsString
(
object
);
}
catch
(
JsonProcessingException
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
<
T
>
T
fromJson
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
json
))
{
throw
new
IllegalArgumentException
(
"Json is null or empty"
);
}
try
{
return
objectMapper
.
readValue
(
json
,
clazz
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
<
T
>
T
fromJson
(
String
json
,
TypeReference
<
T
>
typeReference
)
{
if
(
StringUtils
.
isEmpty
(
json
))
{
throw
new
IllegalArgumentException
(
"Json is null or empty"
);
}
try
{
return
objectMapper
.
readValue
(
json
,
typeReference
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
ObjectMapper
getObjectMapper
()
{
return
objectMapper
;
}
}
\ No newline at end of file
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