All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.annotation.Marshalled Maven / Gradle / Ivy

// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you 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 org.apache.juneau.annotation;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;

import java.lang.annotation.*;

import org.apache.juneau.*;

/**
 * Annotation that can be applied to classes to control how they are marshalled.
 *
 * 

* Can be used in the following locations: *

    *
  • Marshalled classes. *
  • @Rest-annotated classes and @RestOp-annotated methods when an {@link #on()} value is specified. *
* *

* This annotation is typically only applied to non-bean classes. The {@link Bean @Bean} annotation contains equivalent * functionality for bean classes. * *

See Also:
    *
*/ @Documented @Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Repeatable(MarshalledAnnotation.Array.class) @ContextApply(MarshalledAnnotation.Applier.class) public @interface Marshalled { /** * POJO example. * *

* Specifies an example of the specified class in Simplified JSON format. * *

* Examples are used in cases such as POJO examples in Swagger documents. * *

Example:
*

* @Marshalled(example="{foo:'bar'}") * public class MyClass {...} *

* *
Notes:
    *
  • * Setting applies to specified class and all subclasses. *
  • * Keys are the class of the example. *
    Values are JSON 5 representation of that class. *
  • * POJO examples can also be defined on classes via the following: *
      *
    • A static field annotated with {@link Example @Example}. *
    • A static method annotated with {@link Example @Example} with zero arguments or one {@link BeanSession} argument. *
    • A static method with name example with no arguments or one {@link BeanSession} argument. *
    *
  • * Supports VarResolver.DEFAULT (e.g. "$C{myConfigVar}"). *
* *
See Also:
    *
  • {@link Example} *
* * @return The annotation value. */ String example() default ""; /** * Implementation class. * *

* For interfaces and abstract classes this method can be used to specify an implementation class for the * interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a * parse). * *

Example:
*

* @Marshalled(implClass=MyInterfaceImpl.class) * public class MyInterface {...} *

* * @return The annotation value. */ Class implClass() default void.class; /** * Dynamically apply this annotation to the specified classes. * *

* Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class. * It is ignored when the annotation is applied directly to classes. * *

* The following example shows the equivalent methods for applying the {@link Bean @Bean} annotation to REST methods: *

* // Class with explicit annotation. * @Marshalled(example="{foo:'bar'}") * public class A {...} * * // Class with annotation applied via @BeanConfig * public class B {...} * * // Java REST method with @BeanConfig annotation. * @RestOp(...) * @Marshalled(on="B", example="{foo:'bar'}") * public void doFoo() {...} *

* *
Valid patterns:
*
    *
  • Classes: *
      *
    • Fully qualified: *
        *
      • "com.foo.MyClass" *
      *
    • Fully qualified inner class: *
        *
      • "com.foo.MyClass$Inner1$Inner2" *
      *
    • Simple: *
        *
      • "MyClass" *
      *
    • Simple inner: *
        *
      • "MyClass$Inner1$Inner2" *
      • "Inner1$Inner2" *
      • "Inner2" *
      *
    *
  • A comma-delimited list of anything on this list. *
* *
See Also:
* * @return The annotation value. */ String[] on() default {}; /** * Dynamically apply this annotation to the specified classes. * *

* Identical to {@link #on()} except allows you to specify class objects instead of a strings. * *

See Also:
* * @return The annotation value. */ Class[] onClass() default {}; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy