001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.marshall.json;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import java.lang.annotation.*;
022
023import org.apache.juneau.commons.*;
024
025/**
026 * Utility classes and methods for the {@link Json @Json} annotation.
027 *
028 * <h5 class='section'>See Also:</h5><ul>
029 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonSupport">JSON</a>
030 * </ul>
031 */
032public class JsonAnnotation {
033
034   /**
035    * Prevents instantiation.
036    */
037   private JsonAnnotation() {}
038
039   /**
040    * Builder class.
041    *
042    * <h5 class='section'>See Also:</h5><ul>
043    *    <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)}
044    * </ul>
045    */
046   public static class Builder extends AnnotationObject.Builder {
047
048      private String[] description = {};
049      private String wrapperAttr = "";
050
051      /**
052       * Constructor.
053       */
054      protected Builder() {
055         super(Json.class);
056      }
057
058      /**
059       * Instantiates a new {@link Json @Json} object initialized with this builder.
060       *
061       * @return A new {@link Json @Json} object.
062       */
063      public Json build() {
064         return new Object(this);
065      }
066
067      /**
068       * Sets the description property on this annotation.
069       *
070       * @param value The new value for this property.
071       * @return This object.
072       */
073      public Builder description(String...value) {
074         description = value;
075         return this;
076      }
077
078      /**
079       * Sets the {@link Json#wrapperAttr} property on this annotation.
080       *
081       * @param value The new value for this property.
082       * @return This object.
083       */
084      public Builder wrapperAttr(String value) {
085         wrapperAttr = value;
086         return this;
087      }
088
089   }
090
091   @SuppressWarnings({
092      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
093   })
094   private static class Object extends AnnotationObject implements Json {
095
096      private final String[] description;
097      private final String wrapperAttr;
098
099      Object(JsonAnnotation.Builder b) {
100         super(b);
101         description = cp(b.description);
102         wrapperAttr = b.wrapperAttr;
103      }
104
105      @Override /* Overridden from Json */
106      public String wrapperAttr() {
107         return wrapperAttr;
108      }
109
110      @Override /* Overridden from annotation */
111      public String[] description() {
112         return description;
113      }
114   }
115
116   /** Default value */
117   public static final Json DEFAULT = create().build();
118
119   /**
120    * Instantiates a new builder for this class.
121    *
122    * @return A new builder object.
123    */
124   public static Builder create() {
125      return new Builder();
126   }
127}