001/* 002 * Configurate 003 * Copyright (C) zml and Configurate contributors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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.spongepowered.configurate.serialize; 018 019import java.lang.reflect.AnnotatedType; 020import java.lang.reflect.Type; 021 022/** 023 * Error thrown when a value fails to be converted to an expected type. 024 * 025 * @since 4.0.0 026 */ 027public class CoercionFailedException extends SerializationException { 028 029 private static final long serialVersionUID = 5800074754243723221L; 030 031 /** 032 * Indicate that a value transformation has failed. 033 * 034 * @param inputValue original value 035 * @param typeDescription description of the expected type 036 * @since 4.0.0 037 */ 038 public CoercionFailedException(final Object inputValue, final String typeDescription) { 039 super("Failed to coerce input value of type " + inputValue.getClass() + " to " + typeDescription); 040 } 041 042 /** 043 * Indicate that a value transformation has failed. 044 * 045 * @param target expected type 046 * @param inputValue original value 047 * @param typeDescription description of the expected type 048 * @since 4.0.0 049 */ 050 public CoercionFailedException(final Type target, final Object inputValue, final String typeDescription) { 051 super(target, "Failed to coerce input value of type " + inputValue.getClass() + " to " + typeDescription); 052 } 053 054 /** 055 * Indicate that a value transformation has failed. 056 * 057 * @param target expected type 058 * @param inputValue original value 059 * @param typeDescription description of the expected type 060 * @since 4.2.0 061 */ 062 public CoercionFailedException(final AnnotatedType target, final Object inputValue, final String typeDescription) { 063 super(target, "Failed to coerce input value of type " + inputValue.getClass() + " to " + typeDescription); 064 } 065 066}