001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.httppart; 014 015import org.apache.juneau.*; 016import org.apache.juneau.remoteable.*; 017 018/** 019 * Interface used to convert POJOs to simple strings in HTTP headers, query parameters, form-data parameters, and URI 020 * path variables. 021 * 022 * <p> 023 * The following default implementations are provided: 024 * <ul class='doctree'> 025 * <li class='jc'>{@link org.apache.juneau.httppart.UonPartSerializer} - Parts encoded in UON notation. 026 * <li class='jc'>{@link org.apache.juneau.httppart.SimpleUonPartSerializer} - Parts encoded in UON notation, but 027 * strings are treated as plain-text and arrays/collections are serialized as comma-delimited lists. 028 * <li class='jc'>{@link org.apache.juneau.httppart.SimplePartSerializer} - Parts encoded in plain text. 029 * </ul> 030 * 031 * <p> 032 * This class is used in the following locations: 033 * <ul> 034 * <li class='ja'>{@link FormData#serializer()} 035 * <li class='ja'>{@link FormDataIfNE#serializer()} 036 * <li class='ja'>{@link Query#serializer()} 037 * <li class='ja'>{@link QueryIfNE#serializer()} 038 * <li class='ja'>{@link Header#serializer()} 039 * <li class='ja'>{@link HeaderIfNE#serializer()} 040 * <li class='ja'>{@link Path#serializer()} 041 * <li class='ja'>{@link RequestBean#serializer()} 042 * <li class='jc'><code>RestClientBuilder.partSerializer(Class)</code> 043 * </ul> 044 * 045 * <p> 046 * Implementations must include either a public no-args constructor or a public constructor that takes in a single 047 * {@link PropertyStore} object. 048 */ 049public interface HttpPartSerializer { 050 051 /** 052 * Represent "no" part part serializer. 053 * 054 * <p> 055 * Used to represent the absence of a part serializer in annotations. 056 */ 057 public static interface Null extends HttpPartSerializer {} 058 059 /** 060 * Converts the specified value to a string that can be used as an HTTP header value, query parameter value, 061 * form-data parameter, or URI path variable. 062 * 063 * <p> 064 * Returned values should NOT be URL-encoded. 065 * 066 * @param type The category of value being serialized. 067 * @param value The value being serialized. 068 * @return The serialized value. 069 */ 070 public String serialize(HttpPartType type, Object value); 071}