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.bson;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import org.apache.juneau.marshall.*;
025
026/**
027 * Annotation for specifying config properties defined in {@link BsonSerializer} and {@link BsonParser}.
028 *
029 * <p>
030 * Used primarily for specifying bean configuration properties on REST classes and methods.
031 *
032 * <h5 class='section'>See Also:</h5><ul>
033 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Bson">BSON</a>
034 * </ul>
035 */
036@Target({ TYPE, METHOD })
037@Retention(RUNTIME)
038@Inherited
039@ContextApply({ BsonConfigAnnotation.SerializerApply.class, BsonConfigAnnotation.ParserApply.class })
040public @interface BsonConfig {
041
042   /**
043    * Add <js>"_type"</js> properties when needed.
044    *
045    * <p>
046    * If <js>"true"</js>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred
047    * through reflection.
048    *
049    * <ul class='values'>
050    *    <li><js>"true"</js>
051    *    <li><js>"false"</js> (default)
052    * </ul>
053    *
054    * @return The annotation value.
055    */
056   String addBeanTypes() default "";
057
058   /**
059    * Use BSON datetime type for {@link java.util.Date}/{@link java.util.Calendar}/{@link java.time.Instant}.
060    *
061    * <p>
062    * If <js>"true"</js>, dates are serialized as BSON datetime (type 0x09). If <js>"false"</js>, dates are serialized as ISO-8601 strings.
063    *
064    * <ul class='values'>
065    *    <li><js>"true"</js> (default)
066    *    <li><js>"false"</js>
067    * </ul>
068    *
069    * @return The annotation value.
070    */
071   String writeDatesAsDatetime() default "";
072
073   /**
074    * Maximum allowed wire-declared length (in bytes) for BSON strings, binary payloads, and document/array size
075    * prefixes when parsing.
076    *
077    * <p>
078    * Guards against malformed or adversarial input where a small payload declares a huge or negative length.
079    * Default is <js>"16777216"</js> (16 MiB). A value of <js>"0"</js> or less disables the cap.
080    *
081    * @return The annotation value.
082    */
083   String maxLength() default "";
084
085   /**
086    * Optional rank for this config.
087    *
088    * @return The annotation value.
089    */
090   int rank() default 0;
091}