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.serializer.*; 017 018/** 019 * Base class for implementations of {@link HttpPartSerializer} 020 * 021 * <h5 class='section'>Notes:</h5><ul> 022 * <li class='note'>This class is thread safe and reusable. 023 * </ul> 024 * 025 * <h5 class='section'>See Also:</h5><ul> 026 * <li class='link'><a class="doclink" href="../../../../index.html#jm.HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a> 027 * </ul> 028 */ 029public abstract class BaseHttpPartSerializer extends BeanContextable implements HttpPartSerializer { 030 031 //------------------------------------------------------------------------------------------------------------------- 032 // Builder 033 //------------------------------------------------------------------------------------------------------------------- 034 035 /** 036 * Builder class. 037 */ 038 public abstract static class Builder extends BeanContextable.Builder { 039 040 /** 041 * Constructor. 042 */ 043 protected Builder() { 044 } 045 046 /** 047 * Copy constructor. 048 * @param builder The existing builder to copy. 049 */ 050 protected Builder(Builder builder) { 051 super(builder); 052 } 053 } 054 055 //------------------------------------------------------------------------------------------------------------------- 056 // Instance 057 //------------------------------------------------------------------------------------------------------------------- 058 059 /** 060 * Constructor. 061 * 062 * @param builder The builder for this object. 063 */ 064 protected BaseHttpPartSerializer(Builder builder) { 065 super(builder); 066 } 067 068 /** 069 * Converts the specified value to a string that can be used as an HTTP header value, query parameter value, 070 * form-data parameter, or URI path variable. 071 * 072 * <p> 073 * Returned values should NOT be URL-encoded. 074 * 075 * @param partType The category of value being serialized. 076 * @param schema 077 * Schema information about the part. 078 * <br>May be <jk>null</jk>. 079 * <br>Not all part serializers use the schema information. 080 * @param value The value being serialized. 081 * @return The serialized value. 082 * @throws SerializeException If a problem occurred while trying to parse the input. 083 * @throws SchemaValidationException If the output fails schema validation. 084 */ 085 public String serialize(HttpPartType partType, HttpPartSchema schema, Object value) throws SchemaValidationException, SerializeException { 086 return getPartSession().serialize(partType, schema, value); 087 } 088}