Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit de6f8ba0
authored
May 18, 2021
by
王能兵
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
!3
2 parents
5be3f346
96696ad6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
3 deletions
src/main/java/com/glsx/admin/config/FeignDecoderForR.java
src/main/java/com/glsx/admin/config/JacksonMapperConfig.java
src/main/java/com/glsx/admin/config/FeignDecoderForR.java
View file @
de6f8ba
...
@@ -67,9 +67,12 @@ public class FeignDecoderForR extends FeignDecoder<R> {
...
@@ -67,9 +67,12 @@ public class FeignDecoderForR extends FeignDecoder<R> {
PAGE_HELPER_PAGE_INFO
(
PageInfo
.
class
)
{
PAGE_HELPER_PAGE_INFO
(
PageInfo
.
class
)
{
@Override
@Override
public
Object
parse
(
R
resp
,
Type
type
)
{
public
Object
parse
(
R
resp
,
Type
type
)
{
ParameterizedType
parameterizedType
=
(
ParameterizedType
)
type
;
Type
itemType
=
parameterizedType
.
getActualTypeArguments
()[
0
];
JSONObject
dataObj
=
JSON
.
parseObject
(
FeignParserForR
.
extractDataJson
(
resp
));
JSONObject
dataObj
=
JSON
.
parseObject
(
FeignParserForR
.
extractDataJson
(
resp
));
// 先创造出 PageInfo 对象,再填充数据
// 先创造出 PageInfo 对象,再填充数据
PageInfo
<?>
pageInfo
=
PageInfo
.
of
(
dataObj
.
getJSONArray
(
"list"
));
PageInfo
<?>
pageInfo
=
PageInfo
.
of
(
dataObj
.
getJSONArray
(
"list"
)
.
toJavaList
((
Class
<?>)
itemType
));
pageInfo
.
setPages
(
dataObj
.
getInteger
(
"totalPages"
));
pageInfo
.
setPages
(
dataObj
.
getInteger
(
"totalPages"
));
pageInfo
.
setTotal
(
dataObj
.
getLong
(
"totalElements"
));
pageInfo
.
setTotal
(
dataObj
.
getLong
(
"totalElements"
));
return
pageInfo
;
return
pageInfo
;
...
@@ -83,11 +86,11 @@ public class FeignDecoderForR extends FeignDecoder<R> {
...
@@ -83,11 +86,11 @@ public class FeignDecoderForR extends FeignDecoder<R> {
@Override
@Override
public
Object
parse
(
R
resp
,
Type
type
)
{
public
Object
parse
(
R
resp
,
Type
type
)
{
ParameterizedType
parameterizedType
=
(
ParameterizedType
)
type
;
ParameterizedType
parameterizedType
=
(
ParameterizedType
)
type
;
Type
itemType
=
parameterizedType
.
getActualTypeArguments
()[
0
];
JSONObject
dataObj
=
JSON
.
parseObject
(
FeignParserForR
.
extractDataJson
(
resp
));
JSONObject
dataObj
=
JSON
.
parseObject
(
FeignParserForR
.
extractDataJson
(
resp
));
// 解析出 Page 对象,再填充数据
// 解析出 Page 对象,再填充数据
Page
<?>
page
=
dataObj
.
getJSONArray
(
"page"
).
toJavaObject
(
type
);
Page
<?>
page
=
dataObj
.
getJSONArray
(
"page"
).
toJavaObject
(
type
);
page
.
addAll
(
dataObj
.
getJSONArray
(
"items"
).
toJavaObject
(
page
.
addAll
(
dataObj
.
getJSONArray
(
"items"
).
toJavaList
((
Class
)
itemType
));
parameterizedType
.
getActualTypeArguments
()[
0
]));
return
page
;
return
page
;
}
}
},
},
...
...
src/main/java/com/glsx/admin/config/JacksonMapperConfig.java
0 → 100644
View file @
de6f8ba
package
com
.
glsx
.
admin
.
config
;
import
javax.annotation.PostConstruct
;
import
java.text.SimpleDateFormat
;
import
java.util.Map
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.jackson.JacksonProperties
;
import
org.springframework.context.annotation.Configuration
;
/**
* <p>Description: 用于配置 jackson 序列化和反序列化
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-05-14
*/
@Configuration
public
class
JacksonMapperConfig
{
@Autowired
(
required
=
false
)
private
ObjectMapper
objectMapper
;
@Autowired
(
required
=
false
)
private
JacksonProperties
jacksonProperties
;
@PostConstruct
public
void
configJackson
()
{
if
(
objectMapper
!=
null
&&
jacksonProperties
!=
null
)
{
this
.
configSerialization
(
objectMapper
,
jacksonProperties
);
this
.
configDeserialization
(
objectMapper
,
jacksonProperties
);
this
.
configOthers
(
objectMapper
,
jacksonProperties
);
}
}
private
void
configSerialization
(
ObjectMapper
objectMapper
,
JacksonProperties
properties
)
{
Map
<
SerializationFeature
,
Boolean
>
serialization
=
properties
.
getSerialization
();
if
(
serialization
!=
null
)
{
serialization
.
forEach
(
objectMapper:
:
configure
);
}
}
private
void
configDeserialization
(
ObjectMapper
objectMapper
,
JacksonProperties
properties
)
{
Map
<
DeserializationFeature
,
Boolean
>
deserialization
=
properties
.
getDeserialization
();
if
(
deserialization
!=
null
)
{
deserialization
.
forEach
(
objectMapper:
:
configure
);
}
}
private
void
configOthers
(
ObjectMapper
objectMapper
,
JacksonProperties
properties
)
{
if
(
properties
.
getDateFormat
()
!=
null
)
{
objectMapper
.
setDateFormat
(
new
SimpleDateFormat
(
properties
.
getDateFormat
()));
}
if
(
properties
.
getTimeZone
()
!=
null
)
{
objectMapper
.
setTimeZone
(
properties
.
getTimeZone
());
}
if
(
properties
.
getLocale
()
!=
null
)
{
objectMapper
.
setLocale
(
properties
.
getLocale
());
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment