diff --git a/joylive-bom/pom.xml b/joylive-bom/pom.xml
index 7a5fdd05..6a3641aa 100644
--- a/joylive-bom/pom.xml
+++ b/joylive-bom/pom.xml
@@ -93,6 +93,11 @@
joylive-parser-jackson
${revision}
+
+ com.jd.live
+ joylive-parser-fastjson2
+ ${revision}
+
com.jd.live
joylive-parser-properties
diff --git a/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/parser/json/JsonFormat.java b/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/parser/json/JsonFormat.java
index 81046d46..662af462 100644
--- a/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/parser/json/JsonFormat.java
+++ b/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/parser/json/JsonFormat.java
@@ -41,11 +41,4 @@
*/
String pattern() default "";
- /**
- * Specifies the timezone to be used for formatting/parsing the date/time value.
- * This is particularly useful for applications that operate across multiple time zones.
- *
- * @return The ID of the timezone, such as "UTC" or "GMT+10".
- */
- String timezone() default "";
}
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/pom.xml b/joylive-implement/joylive-parser/joylive-parser-fastjson2/pom.xml
index 9a9d61d6..74e35d4a 100644
--- a/joylive-implement/joylive-parser/joylive-parser-fastjson2/pom.xml
+++ b/joylive-implement/joylive-parser/joylive-parser-fastjson2/pom.xml
@@ -10,19 +10,14 @@
2.0.53
- 2.2
-
- org.yaml
- snakeyaml
- ${snakeyaml.version}
-
com.alibaba.fastjson2
fastjson2
${fastjson2.version}
+
@@ -35,7 +30,6 @@
com.alibaba.fastjson2:*
- org.yaml:*
@@ -56,10 +50,6 @@
com.alibaba.fastjson2
com.jd.live.agent.shaded.com.alibaba.fastjson2
-
- org.yaml
- com.jd.live.agent.shaded.org.yaml
-
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/AbstractFastjson2Parser.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/AbstractFastjson2Parser.java
deleted file mode 100644
index f9b2ae0e..00000000
--- a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/AbstractFastjson2Parser.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.jd.live.agent.implement.parser.fastjson2;
-
-import com.alibaba.fastjson2.JSONFactory;
-import com.jd.live.agent.core.exception.ParseException;
-import com.jd.live.agent.core.parser.ConfigParser;
-import com.jd.live.agent.core.parser.ObjectParser;
-import com.jd.live.agent.core.parser.TypeReference;
-import org.yaml.snakeyaml.Yaml;
-
-import java.io.*;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.Map;
-
-public abstract class AbstractFastjson2Parser implements ConfigParser, ObjectParser {
-
- static {
- JSONFactory.getDefaultObjectWriterProvider().register(new JoyLiveWriterModule());
- JSONFactory.getDefaultObjectReaderProvider().register(new JoyLiveReaderModule());
- }
-
- private final Yaml yaml = new Yaml();
-
- @Override
- public Map parse(Reader reader) {
- return Collections.emptyMap();
- }
-
- @Override
- public T read(Reader reader, Class clazz) {
- if (reader == null || clazz == null)
- return null;
- try {
- switch (getSupportedType()) {
- case YAML:
- case YML:
- return com.alibaba.fastjson2.JSON.parseObject(
- com.alibaba.fastjson2.JSON.toJSONString(yaml.load(reader)),
- clazz
- );
- default:
- return com.alibaba.fastjson2.JSON.parseObject(reader, clazz);
- }
- } catch (Exception e) {
- throw new ParseException("read error. caused by " + e.getMessage(), e);
- } finally {
- ProxySupport.cachedKey.remove();
- ProxySupport.jsonConverterThreadLocal.remove();
- ProxySupport.timeFormatThreadLocal.remove();
- }
- }
-
- @Override
- public T read(Reader reader, TypeReference reference) {
- if (reader == null || reference == null)
- return null;
- try {
- switch (getSupportedType()) {
- case YAML:
- case YML:
- return com.alibaba.fastjson2.JSON.parseObject(
- com.alibaba.fastjson2.JSON.toJSONString(yaml.load(reader)),
- reference.getType()
- );
- default:
- return com.alibaba.fastjson2.JSON.parseObject(reader, reference.getType());
- }
- } catch (Exception e) {
- throw new ParseException("read error. caused by " + e.getMessage(), e);
- } finally {
- ProxySupport.cachedKey.remove();
- ProxySupport.jsonConverterThreadLocal.remove();
- ProxySupport.timeFormatThreadLocal.remove();
- }
- }
-
- @Override
- public T read(Reader reader, Type type) {
- if (reader == null || type == null)
- return null;
- try {
- switch (getSupportedType()) {
- case YAML:
- case YML:
- return com.alibaba.fastjson2.JSON.parseObject(
- com.alibaba.fastjson2.JSON.toJSONString(yaml.load(reader)),
- type
- );
- default:
- return com.alibaba.fastjson2.JSON.parseObject(reader, type);
- }
- } catch (Exception e) {
- throw new ParseException("read error. caused by " + e.getMessage(), e);
- } finally {
- ProxySupport.cachedKey.remove();
- ProxySupport.jsonConverterThreadLocal.remove();
- ProxySupport.timeFormatThreadLocal.remove();
- }
- }
-
- @Override
- public void write(Writer writer, Object obj) {
- if (writer == null || obj == null)
- return;
- try {
- ByteArrayOutputStream strStream = new ByteArrayOutputStream();
- com.alibaba.fastjson2.JSON.writeTo(strStream, obj);
- String str = strStream.toString(StandardCharsets.UTF_8.name());
- writer.write(str);
- writer.flush();
- } catch (Exception e) {
- throw new ParseException("write error. caused by " + e.getMessage(), e);
- } finally {
- ProxySupport.cachedKey.remove();
- ProxySupport.jsonConverterThreadLocal.remove();
- ProxySupport.timeFormatThreadLocal.remove();
- }
- }
-
- protected String getSupportedType() {
- return JSON;
- }
-}
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Converters.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Converters.java
new file mode 100644
index 00000000..e4089721
--- /dev/null
+++ b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Converters.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright © ${year} ${owner} (${email})
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jd.live.agent.implement.parser.fastjson2;
+
+import com.jd.live.agent.core.exception.ParseException;
+import com.jd.live.agent.core.parser.json.JsonConverter;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A utility class for managing and creating JSON converters.
+ */
+public class Converters {
+
+ /**
+ * A map of field names to their corresponding JSON converters.
+ */
+ private static final Map> FIELD_CONVERTERS = new ConcurrentHashMap<>();
+
+ /**
+ * A map of converter class names to their corresponding JSON converters.
+ */
+ private static final Map> CONVERTERS = new ConcurrentHashMap<>();
+
+ /**
+ * Gets or creates a JSON converter instance for the given converter class.
+ *
+ * @param clazz The converter class to get or create an instance for.
+ * @return The JSON converter instance, or null if the given class is null.
+ * @throws ParseException If an error occurs while creating the converter instance.
+ */
+ public static JsonConverter, ?> getOrCreateConverter(Class extends JsonConverter, ?>> clazz) {
+ return clazz == null ? null : CONVERTERS.computeIfAbsent(clazz.getName(), key -> {
+ try {
+ Constructor extends JsonConverter, ?>> constructor = clazz.getConstructor();
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ } catch (Throwable e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ });
+ }
+
+ /**
+ * Gets or creates a JSON converter instance for the given field name and converter class.
+ *
+ * @param fieldName The field name to get or create a converter instance for.
+ * @param clazz The converter class to get or create an instance for.
+ * @return The JSON converter instance, or null if either the field name or the converter class is null.
+ */
+ public static JsonConverter, ?> getOrCreateConverter(String fieldName, Class extends JsonConverter, ?>> clazz) {
+ return fieldName == null || clazz == null ? null : FIELD_CONVERTERS.computeIfAbsent(fieldName, name -> getOrCreateConverter(clazz));
+ }
+
+ /**
+ * Gets the JSON converter instance for the given field name.
+ *
+ * @param fieldName The field name to get the converter instance for.
+ * @return The JSON converter instance, or null if no converter instance exists for the given field name.
+ */
+ public static JsonConverter, ?> getConverter(String fieldName) {
+ return fieldName == null ? null : FIELD_CONVERTERS.get(fieldName);
+ }
+
+}
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonParser.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonParser.java
index 17fc2fd0..1d35a9bb 100644
--- a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonParser.java
+++ b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonParser.java
@@ -1,30 +1,77 @@
+/*
+ * Copyright © ${year} ${owner} (${email})
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.jd.live.agent.implement.parser.fastjson2;
-import com.alibaba.fastjson2.JSONPath;
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.JSONReader;
+import com.alibaba.fastjson2.JSONWriter;
+import com.jd.live.agent.core.exception.ParseException;
import com.jd.live.agent.core.extension.annotation.Extension;
-import com.jd.live.agent.core.parser.JsonPathParser;
import com.jd.live.agent.core.parser.ObjectParser;
+import com.jd.live.agent.core.parser.TypeReference;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.stream.Collectors;
+import java.io.ByteArrayOutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.reflect.Type;
@Extension(value = ObjectParser.JSON, provider = "fastjson2")
-public class Fastjson2JsonParser extends AbstractFastjson2Parser implements JsonPathParser {
+public class Fastjson2JsonParser implements ObjectParser {
+
+ static {
+ JSONFactory.getDefaultObjectWriterProvider().register(new JoyLiveWriterModule());
+ JSONFactory.getDefaultObjectReaderProvider().register(new JoyLiveReaderModule());
+ }
+
+ @Override
+ public T read(Reader reader, Class clazz) {
+ try {
+ return com.alibaba.fastjson2.JSON.parseObject(reader, clazz, JSONReader.Feature.FieldBased);
+ } catch (Exception e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public T read(Reader reader, TypeReference reference) {
+ try {
+ return com.alibaba.fastjson2.JSON.parseObject(reader, reference.getType(), JSONReader.Feature.FieldBased);
+ } catch (Exception e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
@Override
- public T read(String reader, String path) {
- return (T) JSONPath.eval(reader, path);
+ public T read(Reader reader, Type type) {
+ try {
+ return com.alibaba.fastjson2.JSON.parseObject(reader, type, JSONReader.Feature.FieldBased);
+ } catch (Exception e) {
+ throw new ParseException(e.getMessage(), e);
+ }
}
@Override
- public T read(InputStream in, String path) {
- return (T) JSONPath.eval(
- new BufferedReader(new InputStreamReader(in))
- .lines()
- .collect(Collectors.joining(System.lineSeparator())),
- path);
+ public void write(Writer writer, Object obj) {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream(1000);
+ try {
+ com.alibaba.fastjson2.JSON.writeTo(stream, obj, JSONWriter.Feature.FieldBased);
+ writer.write(stream.toString());
+ } catch (Throwable e) {
+ throw new ParseException(e.getMessage(), e);
+ }
}
}
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonPathParser.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonPathParser.java
new file mode 100644
index 00000000..fbb90215
--- /dev/null
+++ b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2JsonPathParser.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright © ${year} ${owner} (${email})
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jd.live.agent.implement.parser.fastjson2;
+
+import com.alibaba.fastjson2.JSONPath;
+import com.jd.live.agent.core.exception.ParseException;
+import com.jd.live.agent.core.extension.annotation.Extension;
+import com.jd.live.agent.core.parser.JsonPathParser;
+import com.jd.live.agent.core.util.IOUtils;
+
+import java.io.InputStream;
+
+@Extension(value = "fastjson2", order = 1)
+public class Fastjson2JsonPathParser implements JsonPathParser {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T read(String reader, String path) {
+ try {
+ return (T) JSONPath.eval(reader, path);
+ } catch (Throwable e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T read(InputStream in, String path) {
+ try {
+ byte[] buffer = IOUtils.read(in);
+ return (T) JSONPath.eval(new String(buffer), path);
+ } catch (Throwable e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
+}
+
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2YamlParser.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2YamlParser.java
deleted file mode 100644
index 1b859e56..00000000
--- a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/Fastjson2YamlParser.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.jd.live.agent.implement.parser.fastjson2;
-
-import com.jd.live.agent.core.extension.annotation.Extension;
-import com.jd.live.agent.core.parser.ObjectParser;
-
-@Extension(value = {ObjectParser.YAML, ObjectParser.YML}, provider = "fastjson2")
-public class Fastjson2YamlParser extends AbstractFastjson2Parser {
- @Override
- protected String getSupportedType() {
- return "YAML";
- }
-}
\ No newline at end of file
diff --git a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/JoyLiveReaderModule.java b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/JoyLiveReaderModule.java
index bbae5cb2..6c8339a7 100644
--- a/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/JoyLiveReaderModule.java
+++ b/joylive-implement/joylive-parser/joylive-parser-fastjson2/src/main/java/com/jd/live/agent/implement/parser/fastjson2/JoyLiveReaderModule.java
@@ -1,63 +1,65 @@
+/*
+ * Copyright © ${year} ${owner} (${email})
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.jd.live.agent.implement.parser.fastjson2;
+import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.codec.FieldInfo;
import com.alibaba.fastjson2.modules.ObjectReaderAnnotationProcessor;
import com.alibaba.fastjson2.modules.ObjectReaderModule;
+import com.alibaba.fastjson2.reader.ObjectReader;
import com.alibaba.fastjson2.util.BeanUtils;
import com.jd.live.agent.core.parser.json.*;
-import com.jd.live.agent.implement.parser.fastjson2.proxy.object.ProxyObjectReader;
-import com.jd.live.agent.implement.parser.fastjson2.proxy.time.ProxyTimeReader;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Stack;
+import java.lang.reflect.Type;
-import static com.alibaba.fastjson2.util.BeanUtils.getAnnotations;
+import static com.jd.live.agent.implement.parser.fastjson2.Converters.getConverter;
+/**
+ * A module for the ObjectReader that handles custom annotations for JSON deserialization.
+ */
public class JoyLiveReaderModule implements ObjectReaderModule {
- final JoyLiveReadAnnotationProcessor annotationProcessor;
-
public JoyLiveReaderModule() {
- this.annotationProcessor = new JoyLiveReadAnnotationProcessor();
}
public ObjectReaderAnnotationProcessor getAnnotationProcessor() {
- return annotationProcessor;
+ return JoyLiveReadAnnotationProcessor.INSTANCE;
}
- public class JoyLiveReadAnnotationProcessor implements ObjectReaderAnnotationProcessor {
- @Override
- public void getFieldInfo(FieldInfo fieldInfo, Class objectClass, Method method) {
- String methodName = method.getName();
- String fieldName;
-
- if (methodName.startsWith("set")) {
- fieldName = BeanUtils.setterName(methodName, null);
- } else {
- fieldName = BeanUtils.getterName(methodName, null);
- }
+ /**
+ * A private static class that implements the ObjectReaderAnnotationProcessor interface.
+ */
+ private static class JoyLiveReadAnnotationProcessor implements ObjectReaderAnnotationProcessor {
- BeanUtils.declaredFields(objectClass, field -> {
- if (field.getName().equals(fieldName)) {
- int modifiers = field.getModifiers();
- if (!Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
- Annotation[] annotations = getAnnotations(field);
- processAnnotation(fieldInfo, annotations, field);
- }
- }
- });
- }
+ private static final JoyLiveReadAnnotationProcessor INSTANCE = new JoyLiveReadAnnotationProcessor();
@Override
public void getFieldInfo(FieldInfo fieldInfo, Class objectClass, Field field) {
- Annotation[] annotations = getAnnotations(field);
- processAnnotation(fieldInfo, annotations, field);
+ processAnnotation(fieldInfo, BeanUtils.getAnnotations(field), field);
}
+ /**
+ * Processes the annotations for a given field.
+ *
+ * @param fieldInfo The field information.
+ * @param annotations The annotations on the field.
+ * @param field The field being processed.
+ */
private void processAnnotation(FieldInfo fieldInfo, Annotation[] annotations, Field field) {
for (Annotation annotation : annotations) {
Class extends Annotation> annotationType = annotation.annotationType();
@@ -79,64 +81,77 @@ private void processAnnotation(FieldInfo fieldInfo, Annotation[] annotations, Fi
}
}
+ /**
+ * Processes the JsonField annotation on a field.
+ *
+ * @param fieldInfo The field information.
+ * @param jsonField The JsonField annotation.
+ */
private void processJsonField(FieldInfo fieldInfo, JsonField jsonField) {
- String jsonFieldName = jsonField.value();
- if (!jsonFieldName.isEmpty()) {
- fieldInfo.fieldName = jsonFieldName;
- }
+ fieldInfo.fieldName = !jsonField.value().isEmpty() ? jsonField.value() : fieldInfo.fieldName;
}
+ /**
+ * Processes the JsonAlias annotation on a field.
+ *
+ * @param fieldInfo The field information.
+ * @param jsonAlias The JsonAlias annotation.
+ */
private void processJsonAlias(FieldInfo fieldInfo, JsonAlias jsonAlias) {
String[] values = jsonAlias.value();
if (values.length > 0) {
- fieldInfo.alternateNames = values;
+ String[] alternateNames = fieldInfo.alternateNames;
+ if (alternateNames == null || alternateNames.length == 0) {
+ fieldInfo.alternateNames = values;
+ } else {
+ String[] newValues = new String[alternateNames.length + values.length];
+ System.arraycopy(alternateNames, 0, newValues, 0, alternateNames.length);
+ System.arraycopy(values, 0, newValues, alternateNames.length, values.length);
+ fieldInfo.alternateNames = newValues;
+ }
}
}
+ /**
+ * Processes the JsonFormat annotation on a field.
+ *
+ * @param fieldInfo The field information.
+ * @param jsonFormat The JsonFormat annotation.
+ * @param field The field being processed.
+ */
private void processJsonFormat(FieldInfo fieldInfo, JsonFormat jsonFormat, Field field) {
- String pattern = jsonFormat.pattern();
- String timezone = jsonFormat.timezone();
- String typeName = field.getType().getName();
- String fieldName = field.getName();
- boolean typeMatch = "java.util.Date".equals(typeName) ||
- "java.util.Calendar".equals(typeName) ||
- "java.time.ZonedDateTime".equals(typeName) ||
- "java.time.OffsetDateTime".equals(typeName) ||
- "java.time.OffsetTime".equals(typeName);
- if (typeMatch) {
- String cachedKey = field.getDeclaringClass().getName() + "." + field.getName();
- if (!ProxySupport.cachedKey.get().contains(cachedKey)) {
- ProxySupport.timeFormatThreadLocal.get().computeIfAbsent(fieldName, key -> new Stack<>())
- .push(new String[]{pattern, timezone});
- ProxySupport.cachedKey.get().add(cachedKey);
- }
- fieldInfo.readUsing = ProxyTimeReader.class;
- } else {
- fieldInfo.format = pattern;
- }
+ fieldInfo.format = jsonFormat.pattern();
}
+ /**
+ * Processes the DeserializeConverter annotation on a field.
+ *
+ * @param fieldInfo The field information.
+ * @param deserializeConverter The DeserializeConverter annotation.
+ * @param field The field being processed.
+ */
private void processDeserializerConverter(FieldInfo fieldInfo, DeserializeConverter deserializeConverter, Field field) {
- try {
- Class extends JsonConverter, ?>> clazz = deserializeConverter.value();
- String className = clazz.getName();
-
- ProxySupport.jsonConverterThreadLocal.get().computeIfAbsent(field.getName(), key -> new Stack<>())
- .push(
- ProxySupport.converterMap.computeIfAbsent(className, key -> {
- try {
- Constructor extends JsonConverter, ?>> constructor = clazz.getConstructor();
- constructor.setAccessible(true);
- return constructor.newInstance();
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- })
- );
- fieldInfo.readUsing = ProxyObjectReader.class;
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ Class extends JsonConverter, ?>> clazz = deserializeConverter.value();
+ String name = field.getName() + "@" + field.getType().getTypeName();
+ Converters.getOrCreateConverter(name, clazz);
+ fieldInfo.readUsing = ProxyObjectReader.class;
+ }
+ }
+
+ /**
+ * A proxy object reader that uses custom converters for deserialization.
+ */
+ public static class ProxyObjectReader implements ObjectReader
+
+ com.jd.live
+ joylive-parser-fastjson2
+
com.jd.live
joylive-parser-properties
diff --git a/joylive-package/src/main/assembly/assembly.xml b/joylive-package/src/main/assembly/assembly.xml
index 5c90ea18..f4691440 100644
--- a/joylive-package/src/main/assembly/assembly.xml
+++ b/joylive-package/src/main/assembly/assembly.xml
@@ -60,6 +60,7 @@
com.jd.live:joylive-function-bkdrhash
com.jd.live:joylive-logger-slf4j
com.jd.live:joylive-parser-jackson
+ com.jd.live:joylive-parser-fastjson2
com.jd.live:joylive-parser-properties
com.jd.live:joylive-service-file
com.jd.live:joylive-service-multilive