Can I use an annotation to modify a annotated property?

半世苍凉 提交于 2019-12-11 18:32:35

问题


Given

class MyPOJO {
    @XssSanitized()
    String name
}

@Retention(RetentionPolicy.RUNTIME)
@interface XssSanitized {

}

import org.aspectj.lang.annotation.Aspect

@Aspect
@Slf4j
@Component
class XssSanitizedAspect {

    @Around("@within(com.es.phoenix.services.security.XssSanitized))")
    void sanitize(){
        //capture the value of the annotated String
        //make an arbritary change to the string
        //return modified string or otherwise overwrite the property
            log.info("XssSanitizedAspect is working!!!!")
    }
}

Is it possible to modify the property myPOJOObject.name inside of XssSanitizedAspect?

In reality, I need a way to XSS sanitize String properties. I tried creating a custom Jackson Deserializer. It worked, but I cannot inject a feature toggle (without a workaround that breaks all the contracts with the UI) so that solution failed me.

I've gone through numerous examples online. I have not found an example where the annotated property has it's value directly modified in such a way.

来源:https://stackoverflow.com/questions/46592018/can-i-use-an-annotation-to-modify-a-annotated-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!