How to create an annotation that is a group of Jackson annotations?

前端 未结 2 1778
别跟我提以往
别跟我提以往 2020-12-13 06:17

A year or so I read an article that explained how I could create an annotation that basically is a container for other annotations. This way if I always use the same 5 annot

2条回答
  •  孤街浪徒
    2020-12-13 06:53

    There are some examples here on how to make various combinations of annotations containing other annotations. Is this what you're looking for?

    Example from the source:

    @Target(ElementType.METHOD)
    public @interface SimpleAnnotation {
        public String a();
        public int b();
    )
    
    @Target(ElementType.METHOD)
    public @interface ReallyComplexAnnotation {
        public SimpleAnnotation[] value();
    )
    

    Used like this:

    @ReallyComplexAnnotation(
        { @SimpleAnnotation(a="...", b=3), @SimpleAnnotation(a="...", b=4) }
    )
    

提交回复
热议问题