WorkflowConfigMapper.java 文件源码

java
阅读 21 收藏 0 点赞 0 评论 0

项目:workflowTools 作者:
private void serializeConfigurableProperties(JsonObject configJsonObject, Object configInstance, JsonSerializationContext jsonSerializationContext) {
    List<Field> configurableFields = Arrays.stream(configInstance.getClass().getFields())
            .filter(field -> field.getAnnotation(ConfigurableProperty.class) != null).collect(Collectors.toList());

    configurableFields.forEach(field -> {
        String fieldName = determineNameToUseForField(field);
        Object fieldValue = ReflectionUtils.getValue(field, configInstance);
        if (fieldValue != null) {
            JsonElement fieldJsonObject;
            if (field.getAnnotation(JsonAdapter.class) != null) {
                try {
                    JsonSerializer customSerializer = (JsonSerializer) field.getAnnotation(JsonAdapter.class).value().newInstance();
                    fieldJsonObject = customSerializer.serialize(fieldValue, field.getType(), jsonSerializationContext);
                } catch (InstantiationException | IllegalAccessException e) {
                    throw new RuntimeReflectiveOperationException(e);
                }
            } else {
                fieldJsonObject = jsonSerializationContext.serialize(fieldValue);
            }
            configJsonObject.add(fieldName, fieldJsonObject);
        }
    });
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号