¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill åºéª (smallchill@163.com) |
| | | */ |
| | | package org.springblade.core.tool.jackson; |
| | | |
| | | import com.fasterxml.jackson.core.JsonParser; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.TreeNode; |
| | | import com.fasterxml.jackson.core.json.JsonReadFeature; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.*; |
| | | import com.fasterxml.jackson.databind.type.CollectionLikeType; |
| | | import com.fasterxml.jackson.databind.type.MapType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springframework.lang.Nullable; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Jacksonå·¥å
·ç±» |
| | | * |
| | | * @author Chill |
| | | */ |
| | | @Slf4j |
| | | public class JsonUtil { |
| | | |
| | | /** |
| | | * å°å¯¹è±¡åºååæjsonå符串 |
| | | * |
| | | * @param value javaBean |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static <T> String toJson(T value) { |
| | | try { |
| | | return getInstance().writeValueAsString(value); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡åºååæ json byte æ°ç» |
| | | * |
| | | * @param object javaBean |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static byte[] toJsonAsBytes(Object object) { |
| | | try { |
| | | return getInstance().writeValueAsBytes(object); |
| | | } catch (JsonProcessingException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param content content |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(String content, Class<T> valueType) { |
| | | try { |
| | | return getInstance().readValue(content, valueType); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param content content |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(String content, TypeReference<T> typeReference) { |
| | | try { |
| | | return getInstance().readValue(content, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°json byte æ°ç»ååºååæå¯¹è±¡ |
| | | * |
| | | * @param bytes json bytes |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(byte[] bytes, Class<T> valueType) { |
| | | try { |
| | | return getInstance().readValue(bytes, valueType); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param bytes bytes |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(byte[] bytes, TypeReference<T> typeReference) { |
| | | try { |
| | | return getInstance().readValue(bytes, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(InputStream in, Class<T> valueType) { |
| | | try { |
| | | return getInstance().readValue(in, valueType); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T parse(InputStream in, TypeReference<T> typeReference) { |
| | | try { |
| | | return getInstance().readValue(in, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæList对象 |
| | | * |
| | | * @param content content |
| | | * @param valueTypeRef class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return List<T> |
| | | */ |
| | | public static <T> List<T> parseArray(String content, Class<T> valueTypeRef) { |
| | | try { |
| | | |
| | | if (!StringUtil.startsWithIgnoreCase(content, StringPool.LEFT_SQ_BRACKET)) { |
| | | content = StringPool.LEFT_SQ_BRACKET + content + StringPool.RIGHT_SQ_BRACKET; |
| | | } |
| | | |
| | | List<Map<String, Object>> list = getInstance().readValue(content, new TypeReference<List<Map<String, Object>>>() { |
| | | }); |
| | | |
| | | List<T> result = new ArrayList<>(); |
| | | for (Map<String, Object> map : list) { |
| | | result.add(toPojo(map, valueTypeRef)); |
| | | } |
| | | return result; |
| | | } catch (IOException e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param jsonString jsonString |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(String jsonString) { |
| | | Objects.requireNonNull(jsonString, "jsonString is null"); |
| | | try { |
| | | return getInstance().readTree(jsonString); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param in InputStream |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(InputStream in) { |
| | | Objects.requireNonNull(in, "InputStream in is null"); |
| | | try { |
| | | return getInstance().readTree(in); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param content content |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(byte[] content) { |
| | | Objects.requireNonNull(content, "byte[] content is null"); |
| | | try { |
| | | return getInstance().readTree(content); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param jsonParser JsonParser |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(JsonParser jsonParser) { |
| | | Objects.requireNonNull(jsonParser, "jsonParser is null"); |
| | | try { |
| | | return getInstance().readTree(jsonParser); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å°json byte æ°ç»ååºååæå¯¹è±¡ |
| | | * |
| | | * @param content json bytes |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable byte[] content, Class<T> valueType) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, valueType); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param jsonString jsonString |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable String jsonString, Class<T> valueType) { |
| | | if (StringUtil.isBlank(jsonString)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(jsonString, valueType); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable InputStream in, Class<T> valueType) { |
| | | if (in == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(in, valueType); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param content bytes |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable byte[] content, TypeReference<T> typeReference) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param jsonString jsonString |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable String jsonString, TypeReference<T> typeReference) { |
| | | if (StringUtil.isBlank(jsonString)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(jsonString, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | @Nullable |
| | | public static <T> T readValue(@Nullable InputStream in, TypeReference<T> typeReference) { |
| | | if (in == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | return getInstance().readValue(in, typeReference); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°è£
map type |
| | | * |
| | | * @param keyClass key ç±»å |
| | | * @param valueClass value ç±»å |
| | | * @return MapType |
| | | */ |
| | | public static MapType getMapType(Class<?> keyClass, Class<?> valueClass) { |
| | | return getInstance().getTypeFactory().constructMapType(Map.class, keyClass, valueClass); |
| | | } |
| | | |
| | | /** |
| | | * å°è£
map type |
| | | * |
| | | * @param elementClass éåå¼ç±»å |
| | | * @return CollectionLikeType |
| | | */ |
| | | public static CollectionLikeType getListType(Class<?> elementClass) { |
| | | return getInstance().getTypeFactory().constructCollectionLikeType(List.class, elementClass); |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @param elementClass elementClass |
| | | * @param <T> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <T> List<T> readList(@Nullable byte[] content, Class<T> elementClass) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getListType(elementClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content InputStream |
| | | * @param elementClass elementClass |
| | | * @param <T> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <T> List<T> readList(@Nullable InputStream content, Class<T> elementClass) { |
| | | if (content == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getListType(elementClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @param elementClass elementClass |
| | | * @param <T> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <T> List<T> readList(@Nullable String content, Class<T> elementClass) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getListType(elementClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @param keyClass keyç±»å |
| | | * @param valueClass å¼ç±»å |
| | | * @param <K> æ³å |
| | | * @param <V> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <K, V> Map<K, V> readMap(@Nullable byte[] content, Class<?> keyClass, Class<?> valueClass) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getMapType(keyClass, valueClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content InputStream |
| | | * @param keyClass keyç±»å |
| | | * @param valueClass å¼ç±»å |
| | | * @param <K> æ³å |
| | | * @param <V> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <K, V> Map<K, V> readMap(@Nullable InputStream content, Class<?> keyClass, Class<?> valueClass) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getMapType(keyClass, valueClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @param keyClass keyç±»å |
| | | * @param valueClass å¼ç±»å |
| | | * @param <K> æ³å |
| | | * @param <V> æ³å |
| | | * @return éå |
| | | */ |
| | | public static <K, V> Map<K, V> readMap(@Nullable String content, Class<?> keyClass, Class<?> valueClass) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, getMapType(keyClass, valueClass)); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @return éå |
| | | */ |
| | | public static Map<String, Object> readMap(@Nullable String content) { |
| | | return readMap(content, String.class, Object.class); |
| | | } |
| | | |
| | | /** |
| | | * 读åéå |
| | | * |
| | | * @param content bytes |
| | | * @return éå |
| | | */ |
| | | public static List<Map<String, Object>> readListMap(@Nullable String content) { |
| | | if (ObjectUtil.isEmpty(content)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return getInstance().readValue(content, new TypeReference<List<Map<String, Object>>>() { |
| | | }); |
| | | } catch (IOException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * jackson çç±»åè½¬æ¢ |
| | | * |
| | | * @param fromValue æ¥æºå¯¹è±¡ |
| | | * @param toValueType 转æ¢çç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return 转æ¢ç»æ |
| | | */ |
| | | public static <T> T convertValue(Object fromValue, Class<T> toValueType) { |
| | | return getInstance().convertValue(fromValue, toValueType); |
| | | } |
| | | |
| | | /** |
| | | * jackson çç±»åè½¬æ¢ |
| | | * |
| | | * @param fromValue æ¥æºå¯¹è±¡ |
| | | * @param toValueType 转æ¢çç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return 转æ¢ç»æ |
| | | */ |
| | | public static <T> T convertValue(Object fromValue, JavaType toValueType) { |
| | | return getInstance().convertValue(fromValue, toValueType); |
| | | } |
| | | |
| | | /** |
| | | * jackson çç±»åè½¬æ¢ |
| | | * |
| | | * @param fromValue æ¥æºå¯¹è±¡ |
| | | * @param toValueTypeRef æ³åç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return 转æ¢ç»æ |
| | | */ |
| | | public static <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) { |
| | | return getInstance().convertValue(fromValue, toValueTypeRef); |
| | | } |
| | | |
| | | /** |
| | | * tree 转对象 |
| | | * |
| | | * @param treeNode TreeNode |
| | | * @param valueType valueType |
| | | * @param <T> æ³åæ è®° |
| | | * @return 转æ¢ç»æ |
| | | */ |
| | | public static <T> T treeToValue(TreeNode treeNode, Class<T> valueType) { |
| | | try { |
| | | return getInstance().treeToValue(treeNode, valueType); |
| | | } catch (JsonProcessingException e) { |
| | | throw Exceptions.unchecked(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对象转为 json node |
| | | * |
| | | * @param value 对象 |
| | | * @return JsonNode |
| | | */ |
| | | public static JsonNode valueToTree(@Nullable Object value) { |
| | | return getInstance().valueToTree(value); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦å¯ä»¥åºåå |
| | | * |
| | | * @param value 对象 |
| | | * @return æ¯å¦å¯ä»¥åºåå |
| | | */ |
| | | public static boolean canSerialize(@Nullable Object value) { |
| | | if (value == null) { |
| | | return true; |
| | | } |
| | | return getInstance().canSerialize(value.getClass()); |
| | | } |
| | | |
| | | public static Map<String, Object> toMap(String content) { |
| | | try { |
| | | return getInstance().readValue(content, Map.class); |
| | | } catch (IOException e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static <T> Map<String, T> toMap(String content, Class<T> valueTypeRef) { |
| | | try { |
| | | Map<String, Map<String, Object>> map = getInstance().readValue(content, new TypeReference<Map<String, Map<String, Object>>>() { |
| | | }); |
| | | Map<String, T> result = new HashMap<>(16); |
| | | for (Map.Entry<String, Map<String, Object>> entry : map.entrySet()) { |
| | | result.put(entry.getKey(), toPojo(entry.getValue(), valueTypeRef)); |
| | | } |
| | | return result; |
| | | } catch (IOException e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static <T> T toPojo(Map fromValue, Class<T> toValueType) { |
| | | return getInstance().convertValue(fromValue, toValueType); |
| | | } |
| | | |
| | | public static ObjectMapper getInstance() { |
| | | return JacksonHolder.INSTANCE; |
| | | } |
| | | |
| | | private static class JacksonHolder { |
| | | private static final ObjectMapper INSTANCE = new JacksonObjectMapper(); |
| | | } |
| | | |
| | | private static class JacksonObjectMapper extends ObjectMapper { |
| | | private static final long serialVersionUID = 4288193147502386170L; |
| | | |
| | | private static final Locale CHINA = Locale.CHINA; |
| | | |
| | | public JacksonObjectMapper(ObjectMapper src) { |
| | | super(src); |
| | | } |
| | | |
| | | public JacksonObjectMapper() { |
| | | super(); |
| | | //设置å°ç¹ä¸ºä¸å½ |
| | | super.setLocale(CHINA); |
| | | //廿é»è®¤çæ¶é´æ³æ ¼å¼ |
| | | super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); |
| | | //设置为ä¸å½ä¸æµ·æ¶åº |
| | | super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())); |
| | | //åºååæ¶ï¼æ¥æçç»ä¸æ ¼å¼ |
| | | super.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA)); |
| | | // åå¼å· |
| | | super.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); |
| | | // å
许JSONå符串å
å«éå¼å·æ§å¶å符ï¼å¼å°äº32çASCIIå符ï¼å
å«å¶è¡¨ç¬¦åæ¢è¡ç¬¦ï¼ |
| | | super.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true); |
| | | super.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true); |
| | | super.findAndRegisterModules(); |
| | | //失败å¤ç |
| | | super.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); |
| | | super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| | | //åå¼å·å¤ç |
| | | super.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true); |
| | | //ååºååæ¶ï¼å±æ§ä¸åå¨çå
¼å®¹å¤çs |
| | | super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); |
| | | //æ¥ææ ¼å¼å |
| | | super.registerModule(new BladeJavaTimeModule()); |
| | | super.findAndRegisterModules(); |
| | | } |
| | | |
| | | @Override |
| | | public ObjectMapper copy() { |
| | | return new JacksonObjectMapper(this); |
| | | } |
| | | } |
| | | |
| | | } |