| 1 | package ezvcard.io.json; |
| 2 | |
| 3 | import java.lang.annotation.ElementType; |
| 4 | import java.lang.annotation.Retention; |
| 5 | import java.lang.annotation.RetentionPolicy; |
| 6 | import java.lang.annotation.Target; |
| 7 | |
| 8 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 9 | |
| 10 | import ezvcard.VCard; |
| 11 | import ezvcard.property.ProductId; |
| 12 | |
| 13 | /* |
| 14 | Copyright (c) 2012-2023, Michael Angstadt |
| 15 | All rights reserved. |
| 16 | |
| 17 | Redistribution and use in source and binary forms, with or without |
| 18 | modification, are permitted provided that the following conditions are met: |
| 19 | |
| 20 | 1. Redistributions of source code must retain the above copyright notice, this |
| 21 | list of conditions and the following disclaimer. |
| 22 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 23 | this list of conditions and the following disclaimer in the documentation |
| 24 | and/or other materials provided with the distribution. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 30 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | |
| 37 | The views and conclusions contained in the software and documentation are those |
| 38 | of the authors and should not be interpreted as representing official policies, |
| 39 | either expressed or implied, of the FreeBSD Project. |
| 40 | */ |
| 41 | |
| 42 | /** |
| 43 | * <p> |
| 44 | * Defines settings for how a {@link VCard} should be serialized when written to |
| 45 | * JSON. This annotation should be used in combination with |
| 46 | * {@link JsonSerialize @JsonSerialize} on getter methods that return |
| 47 | * {@link VCard} objects. |
| 48 | * </p> |
| 49 | * <p> |
| 50 | * <b>Example:</b> |
| 51 | * </p> |
| 52 | * |
| 53 | * <pre class="brush:java"> |
| 54 | * class Person { |
| 55 | * private VCard contact; |
| 56 | * |
| 57 | * @JsonSerialize(using = JCardSerializer.class) |
| 58 | * @JCardOptions(addProdId = false, versionStrict = false) |
| 59 | * public VCard getContact() { |
| 60 | * return contact; |
| 61 | * } |
| 62 | * |
| 63 | * //... |
| 64 | * } |
| 65 | * </pre> |
| 66 | * @author Buddy Gorven |
| 67 | */ |
| 68 | @Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE }) |
| 69 | @Retention(RetentionPolicy.RUNTIME) |
| 70 | public @interface JCardFormat { |
| 71 | /** |
| 72 | * Sets whether to add a {@link ProductId} property to the vCard that marks |
| 73 | * it as having been generated by this library (defaults to true). |
| 74 | * @return true to add a {@link ProductId} property, false not to |
| 75 | */ |
| 76 | boolean addProdId() default true; |
| 77 | |
| 78 | /** |
| 79 | * Sets whether to exclude properties that do not support vCard version 4.0 |
| 80 | * from the written vCard (defaults to true). |
| 81 | * @return true to perform the exclusions, false to include everything |
| 82 | */ |
| 83 | boolean versionStrict() default true; |
| 84 | } |