Skip to content

Commit

Permalink
improve: use getObjectMapper().getTypeFactory().constructType instead…
Browse files Browse the repository at this point in the history
…of TypeReference (#6041)

improve: use getObjectMapper().getTypeFactory().constructType insteadof TypeReference
  • Loading branch information
VampireAchao authored Apr 7, 2024
1 parent 5a83b67 commit 8918fea
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Type;

/**
* Jackson 实现 JSON 字段类型处理器
Expand All @@ -51,12 +49,7 @@ public JacksonTypeHandler(Class<?> type, Field field) {
@Override
public Object parse(String json) {
try {
return getObjectMapper().readValue(json, new TypeReference<Object>() {
@Override
public Type getType() {
return getFieldType();
}
});
return getObjectMapper().readValue(json, getObjectMapper().getTypeFactory().constructType(getFieldType()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 8918fea

Please sign in to comment.