public static String toJsonStringByAnnotation(Object object) throws IllegalAccessException {
        JsonType jsonType = JsonType.CONDENSED;
        FieldModifier modifier = FieldModifier.ALL;
        JsonMethod method = JsonMethod.AUTO;
        if (Checker.isNotNull(object)) {
            Class<?> bean = object.getClass();
            if (bean.isAnnotationPresent(ToJsonString.class)) {
                ToJsonString annotation = bean.getAnnotation(ToJsonString.class);
                jsonType = annotation.type();
                modifier = annotation.modifier();
                method = annotation.method();
            }
        }
        String json = toJsonString(object, modifier, method);
        return jsonType == JsonType.PRETTY ? Formatter.formatJson(json) : json;
    }
public static String toJsonStringByAnnotation ( Object object ) throws IllegalAccessException { JsonType jsonType = JsonType . CONDENSED ; FieldModifier modifier = FieldModifier . ALL ; JsonMethod method = JsonMethod . AUTO ; if ( Checker . isNotNull ( object ) ) { Class < ? > bean = object . getClass ( ) ; if ( bean . isAnnotationPresent ( ToJsonString . class ) ) { ToJsonString annotation = bean . getAnnotation ( ToJsonString . class ) ; jsonType = annotation . type ( ) ; modifier = annotation . modifier ( ) ; method = annotation . method ( ) ; } } String json = toJsonString ( object , modifier , method ) ; return jsonType == JsonType . PRETTY ? Formatter . formatJson ( json ) : json ; }
通过注解将Bean转换为JSON

@param object Bean对象

@return {@link String}

@throws IllegalAccessException 异常