Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: use getObjectMapper().getTypeFactory().constructType insteadof TypeReference #6041

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading