Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanbaoming
jiedao-api-boot-master
Commits
2dc1c9f2
Commit
2dc1c9f2
authored
Nov 04, 2024
by
wux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除xmlUtils工具类
parent
ba2b8fe3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
111 deletions
+0
-111
XmlUtils.java
...ava/cn/iocoder/yudao/framework/http/convert/XmlUtils.java
+0
-111
No files found.
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/http/convert/XmlUtils.java
deleted
100644 → 0
View file @
ba2b8fe3
package
cn
.
iocoder
.
yudao
.
framework
.
http
.
convert
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
;
import
com.fasterxml.jackson.dataformat.xml.XmlMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
/**
* XML转换工具类
*
* @author Erwin Feng
* @since 2020-08-13
*/
public
class
XmlUtils
{
private
static
final
XmlMapper
MAPPER
=
new
XmlMapper
();
static
{
configure
(
MAPPER
);
}
public
static
void
configure
(
XmlMapper
mapper
)
{
//枚举输出成字符串
//WRITE_ENUMS_USING_INDEX:输出索引
mapper
.
enable
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
);
//空对象不要抛出异常:
mapper
.
disable
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
);
//Date、Calendar等序列化为时间格式的字符串(如果不执行以下设置,就会序列化成时间戳格式):
mapper
.
disable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
);
//反序列化时,遇到未知属性不要抛出异常:
mapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
//反序列化时,遇到忽略属性不要抛出异常:
mapper
.
disable
(
DeserializationFeature
.
FAIL_ON_IGNORED_PROPERTIES
);
//反序列化时,空字符串对于的实例属性为null:
mapper
.
enable
(
DeserializationFeature
.
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
);
// 采用字段,不使用 Getter
mapper
.
setVisibility
(
PropertyAccessor
.
FIELD
,
JsonAutoDetect
.
Visibility
.
ANY
);
mapper
.
setVisibility
(
PropertyAccessor
.
GETTER
,
JsonAutoDetect
.
Visibility
.
NONE
);
// jackson xml
JacksonXmlModule
jacksonXmlModule
=
new
JacksonXmlModule
();
mapper
.
registerModule
(
jacksonXmlModule
);
// java.time
JavaTimeModule
javaTimeModule
=
new
JavaTimeModule
();
mapper
.
registerModule
(
javaTimeModule
);
}
/**
* 将对象转换成XML格式的字符串
*
* @param value 待转换的对象
* @param <T> 对象的类型
* @return 返回转换后的XML格式的字符串
*/
public
static
<
T
>
String
string
(
T
value
)
{
try
{
return
MAPPER
.
writeValueAsString
(
value
);
}
catch
(
JsonProcessingException
e
)
{
// PrintUtils.error(ExceptionUtils.getStackTrace(e));
return
null
;
}
}
/**
* 将XML格式的字符串转换成对象
*
* @param value 待转换的XML格式的字符串
* @param valueType 转换后的对象的class
* @param <T> 对象的类型
* @return 返回转换后的对象
*/
public
static
<
T
>
T
object
(
String
value
,
Class
<
T
>
valueType
)
{
try
{
return
MAPPER
.
readValue
(
value
,
valueType
);
}
catch
(
JsonProcessingException
e
)
{
// PrintUtils.error(ExceptionUtils.getStackTrace(e));
return
null
;
}
}
/**
* 将XML格式的字符串转换成对象
*
* @param value 待转换的XML格式的字符串
* @param valueType {@link TypeReference}
* @param <T> 对象的类型
* @return 返回转换后的对象
*/
public
static
<
T
>
T
object
(
String
value
,
TypeReference
<
T
>
valueType
)
{
try
{
return
MAPPER
.
readValue
(
value
,
valueType
);
}
catch
(
JsonProcessingException
e
)
{
// PrintUtils.error(ExceptionUtils.getStackTrace(e));
return
null
;
}
}
}
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