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.httppart;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024/**
025 * Specifies the {@link HttpPartSerializer} and {@link HttpPartParser} to use for serializing/parsing HTTP parts.
026 *
027 * <p>
028 * Can be applied alongside the HTTP-part parameter annotations <ja>@Query</ja>, <ja>@Header</ja>, <ja>@FormData</ja>,
029 * and <ja>@Path</ja> to override the default part serializer for that specific value.  It may also be declared at the
030 * method or interface level to supply a default for all parts of that scope.
031 *
032 * <p>
033 * The next-generation {@code org.apache.juneau.rest.client.RestClient} remote-proxy engine
034 * ({@code RestClient.remote(Class)}) honors the {@link #serializer()} attribute for outgoing HTTP <i>parts</i>
035 * (query / header / path / form-data), resolving the most-specific declaration: parameter-level overrides
036 * method-level, which overrides interface-level.  When absent, the client's default part serializer is used
037 * (behavior is unchanged).
038 *
039 * <p>
040 * <b>Not currently consumed:</b> the {@link #parser()} attribute (the next-gen engine has no response-part parsing
041 * path; response bodies are handled by the client {@code Parser}s, not part parsers), the request body (<ja>@Content</ja>,
042 * which uses a full {@code Serializer}/{@code Parser} rather than a part serializer/parser), and the classic
043 * {@code RestClient} remote-proxy path (which does not discover this annotation).
044 *
045 * <h5 class='section'>Example:</h5>
046 * <p class='bjava'>
047 *    <ja>@RemoteGet</ja>(<js>"/mymethod"</js>)
048 *    String myMethod(<ja>@Query</ja>(<js>"foo"</js>) <ja>@HttpPartMarshalling</ja>(serializer=MySerializer.<jk>class</jk>) String <jv>foo</jv>);
049 * </p>
050 *
051 * <h5 class='section'>See Also:</h5><ul>
052 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a>
053 * </ul>
054 */
055@Documented
056@Target({ PARAMETER, METHOD, TYPE, FIELD })
057@Retention(RUNTIME)
058public @interface HttpPartMarshalling {
059
060   /**
061    * Specifies the {@link HttpPartParser} class used for parsing strings to values.
062    *
063    * @return The annotation value.
064    */
065   Class<? extends HttpPartParser> parser() default HttpPartParser.Void.class;
066
067   /**
068    * Specifies the {@link HttpPartSerializer} class used for serializing values to strings.
069    *
070    * @return The annotation value.
071    */
072   Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Void.class;
073}