MCPcopy Create free account
hub / github.com/diyhi/bbs / toGenericObject

Method toGenericObject

src/main/java/cms/component/JsonComponent.java:26–42  ·  view source on GitHub ↗

JSON串转换为Java泛型对象 @param jsonString JSON字符串 @param tr TypeReference,例如: new TypeReference< List >(){} @return List对象列表

(String jsonString, TypeReference<T> tr)

Source from the content-addressed store, hash-verified

24 * @return List对象列表
25 */
26 public <T> T toGenericObject(String jsonString, TypeReference<T> tr) {
27
28 if (jsonString == null || jsonString.isEmpty()) {
29 return null;
30 } else {
31 try {
32 return objectMapper.readValue(jsonString, tr);
33 } catch (Exception e) {
34 // e.printStackTrace();
35 if (logger.isErrorEnabled()) {
36 logger.error("JSON串转换为Java泛型对象",e);
37 }
38
39 }
40 }
41 return null;
42 }
43
44 /**
45 * Java对象转Json字符串

Callers 15

getUserResourceGroupMethod · 0.80
updateQuestionIndexMethod · 0.80
addAllQuestionIndexMethod · 0.80
sendSms_codeMethod · 0.80
deleteQuestionFileMethod · 0.80
resolveConfigObjectMethod · 0.80
getSectionListMethod · 0.80
addRiskSensitiveWordsMethod · 0.80

Calls 1

isEmptyMethod · 0.45

Tested by

no test coverage detected