From 48fde89cd1f34ba8e1ea58df2ddf3aa8ef642701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=A2=A6=E6=8A=80=E6=9C=AF?= <596392912@qq.com> Date: Tue, 12 Mar 2024 20:52:27 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E5=96=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/tool/jackson/JsonUtil.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/JsonUtil.java b/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/JsonUtil.java index d739494..ebffab3 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/JsonUtil.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/JsonUtil.java @@ -403,6 +403,86 @@ public class JsonUtil { } } + /** + * 将json反序列化成对象 + * + * @param content bytes + * @param javaType JavaType + * @param T 泛型标记 + * @return Bean + */ + @Nullable + public static T readValue(@Nullable byte[] content, JavaType javaType) { + if (content == null || content.length == 0) { + return null; + } + try { + return getInstance().readValue(content, javaType); + } catch (IOException e) { + throw Exceptions.unchecked(e); + } + } + + /** + * 将json反序列化成对象 + * + * @param jsonString jsonString + * @param javaType JavaType + * @param T 泛型标记 + * @return Bean + */ + @Nullable + public static T readValue(@Nullable String jsonString, JavaType javaType) { + if (StringUtil.isBlank(jsonString)) { + return null; + } + try { + return getInstance().readValue(jsonString, javaType); + } catch (IOException e) { + throw Exceptions.unchecked(e); + } + } + + /** + * 将json反序列化成对象 + * + * @param in InputStream + * @param javaType JavaType + * @param T 泛型标记 + * @return Bean + */ + @Nullable + public static T readValue(@Nullable InputStream in, JavaType javaType) { + if (in == null) { + return null; + } + try { + return getInstance().readValue(in, javaType); + } catch (IOException e) { + throw Exceptions.unchecked(e); + } + } + + /** + * 将java.io.Reader反序列化成对象 + * + * @param reader java.io.Reader + * @param javaType JavaType + * @param T 泛型标记 + * @return Bean + */ + @Nullable + public static T readValue(@Nullable Reader reader, JavaType javaType) { + if (reader == null) { + return null; + } + try { + return getInstance().readValue(reader, javaType); + } catch (IOException e) { + throw Exceptions.unchecked(e); + } + } + /** * clazz 获取 JavaType *