1 /* 2 * Copyright 2011 Christopher Pheby 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.jadira.bindings.core.binder; 17 18 import java.lang.annotation.Annotation; 19 20 public interface StringBinder { 21 22 /** 23 * Convert a String to the given target class 24 * @param output The target class to convert the object to 25 * @param object The String to be converted 26 * @param <T> The type of the target class 27 * @return An instance of the target class 28 */ 29 <T> T convertFromString(Class<T> output, String object); 30 31 /** 32 * Convert a String to the given target class 33 * @param output The target class to convert the object to 34 * @param object The String to be converted 35 * @param qualifier The qualifier for which the binding must be registered 36 * @param <T> The type of the target class 37 * @return An instance of the target class 38 */ 39 <T> T convertFromString(Class<T> output, String object, Class<? extends Annotation> qualifier); 40 41 /** 42 * Convert an object to String 43 * This method infers the source type for the conversion from the runtime type of object. 44 * @param object The object to be converted 45 * @return A String 46 */ 47 String convertToString(Object object); 48 49 /** 50 * Convert an object to String 51 * This method infers the source type for the conversion from the runtime type of object. 52 * @param object The object to be converted 53 * @param qualifier The qualifier for which the binding must be registered 54 * @return A String 55 */ 56 String convertToString(Object object, Class<? extends Annotation> qualifier); 57 58 /** 59 * Convert an object which is an instance of source class to String 60 * @param input The class of the object to be converted 61 * @param object The object to be converted 62 * @param <S> The type of the input class 63 * @return A String 64 */ 65 <S> String convertToString(Class<S> input, Object object); 66 67 /** 68 * Convert an object which is an instance of source class to String 69 * @param input The class of the object to be converted 70 * @param object The object to be converted 71 * @param qualifier Match the converter with the given qualifier 72 * @param <S> The type of the input class 73 * @return A String 74 */ 75 <S> String convertToString(Class<S> input, Object object, Class<? extends Annotation> qualifier); 76 }