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.json.annotation; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023 024import org.apache.juneau.annotation.*; 025import org.apache.juneau.json.*; 026import org.apache.juneau.serializer.*; 027 028/** 029 * Annotation for specifying config properties defined in {@link JsonSerializer} and {@link JsonParser}. 030 * 031 * <p> 032 * Used primarily for specifying bean configuration properties on REST classes and methods. 033 * 034 * <h5 class='section'>See Also:</h5><ul> 035 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonBasics">JSON Basics</a> 036 * </ul> 037 */ 038@Target({TYPE,METHOD}) 039@Retention(RUNTIME) 040@Inherited 041@ContextApply({JsonConfigAnnotation.SerializerApply.class,JsonConfigAnnotation.ParserApply.class}) 042public @interface JsonConfig { 043 044 /** 045 * Optional rank for this config. 046 * 047 * <p> 048 * Can be used to override default ordering and application of config annotations. 049 * 050 * @return The annotation value. 051 */ 052 int rank() default 0; 053 054 //------------------------------------------------------------------------------------------------------------------- 055 // JsonCommon 056 //------------------------------------------------------------------------------------------------------------------- 057 058 //------------------------------------------------------------------------------------------------------------------- 059 // JsonParser 060 //------------------------------------------------------------------------------------------------------------------- 061 062 /** 063 * Validate end. 064 * 065 * <p> 066 * If <js>"true"</js>, after parsing a POJO from the input, verifies that the remaining input in 067 * the stream consists of only comments or whitespace. 068 * 069 * <ul class='values'> 070 * <li><js>"true"</js> 071 * <li><js>"false"</js> (default) 072 * </ul> 073 * 074 * <h5 class='section'>Notes:</h5><ul> 075 * <li class='note'> 076 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 077 * </ul> 078 * 079 * <h5 class='section'>See Also:</h5><ul> 080 * <li class='jm'>{@link org.apache.juneau.json.JsonParser.Builder#validateEnd()} 081 * </ul> 082 * 083 * @return The annotation value. 084 */ 085 String validateEnd() default ""; 086 087 //------------------------------------------------------------------------------------------------------------------- 088 // JsonSerializer 089 //------------------------------------------------------------------------------------------------------------------- 090 091 /** 092 * Add <js>"_type"</js> properties when needed. 093 * 094 * <p> 095 * If <js>"true"</js>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred 096 * through reflection. 097 * 098 * <p> 099 * When present, this value overrides the {@link org.apache.juneau.serializer.Serializer.Builder#addBeanTypes()} setting and is 100 * provided to customize the behavior of specific serializers in a {@link SerializerSet}. 101 * 102 * <ul class='values'> 103 * <li><js>"true"</js> 104 * <li><js>"false"</js> (default) 105 * </ul> 106 * 107 * <h5 class='section'>Notes:</h5><ul> 108 * <li class='note'> 109 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 110 * </ul> 111 * 112 * <h5 class='section'>See Also:</h5><ul> 113 * <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#addBeanTypesJson()} 114 * </ul> 115 * 116 * @return The annotation value. 117 */ 118 String addBeanTypes() default ""; 119 120 /** 121 * Prefix solidus <js>'/'</js> characters with escapes. 122 * 123 * <p> 124 * If <js>"true"</js>, solidus (e.g. slash) characters should be escaped. 125 * The JSON specification allows for either format. 126 * <br>However, if you're embedding JSON in an HTML script tag, this setting prevents confusion when trying to serialize 127 * <xt><\/script></xt>. 128 * 129 * <ul class='values'> 130 * <li><js>"true"</js> 131 * <li><js>"false"</js> (default) 132 * </ul> 133 * 134 * <h5 class='section'>Notes:</h5><ul> 135 * <li class='note'> 136 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 137 * </ul> 138 * 139 * <h5 class='section'>See Also:</h5><ul> 140 * <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#escapeSolidus()} 141 * </ul> 142 * 143 * @return The annotation value. 144 */ 145 String escapeSolidus() default ""; 146 147 /** 148 * Simple JSON attribute mode. 149 * 150 * <p> 151 * If <js>"true"</js>, JSON attribute names will only be quoted when necessary. 152 * <br>Otherwise, they are always quoted. 153 * 154 * <p> 155 * Attributes do not need to be quoted when they conform to the following: 156 * <ol class='spaced-list'> 157 * <li>They start with an ASCII character or <js>'_'</js>. 158 * <li>They contain only ASCII characters or numbers or <js>'_'</js>. 159 * <li>They are not one of the following reserved words: 160 * <p class='bcode'> 161 * arguments, break, case, catch, class, const, continue, debugger, default, 162 * delete, do, else, enum, eval, export, extends, false, finally, for, function, 163 * if, implements, import, in, instanceof, interface, let, new, null, package, 164 * private, protected, public, return, static, super, switch, this, throw, 165 * true, try, typeof, var, void, while, with, undefined, yield 166 * </p> 167 * </ol> 168 * 169 * <ul class='values'> 170 * <li><js>"true"</js> 171 * <li><js>"false"</js> (default) 172 * </ul> 173 * 174 * <h5 class='section'>Notes:</h5><ul> 175 * <li class='note'> 176 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 177 * </ul> 178 * 179 * <h5 class='section'>See Also:</h5><ul> 180 * <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#simpleAttrs()} 181 * </ul> 182 * 183 * @return The annotation value. 184 */ 185 String simpleAttrs() default ""; 186}