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.Type; 020 021/** 022 * Error thrown when a value fails to be converted to an expected type. 023 * 024 * @since 4.0.0 025 */ 026public class CoercionFailedException extends SerializationException { 027 028 private static final long serialVersionUID = 5800074754243723221L; 029 030 /** 031 * Indicate that a value transformation has failed. 032 * 033 * @param inputValue original value 034 * @param typeDescription description of the expected type 035 * @since 4.0.0 036 */ 037 public CoercionFailedException(final Object inputValue, final String typeDescription) { 038 super("Failed to coerce input value of type " + inputValue.getClass() + " to " + typeDescription); 039 } 040 041 /** 042 * Indicate that a value transformation has failed. 043 * 044 * @param target expected type 045 * @param inputValue original value 046 * @param typeDescription description of the expected type 047 * @since 4.0.0 048 */ 049 public CoercionFailedException(final Type target, final Object inputValue, final String typeDescription) { 050 super(target, "Failed to coerce input value of type " + inputValue.getClass() + " to " + typeDescription); 051 } 052 053}