File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
src/main/java/io/wwan13/wintersecurity/resolve/util Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17- package io .wwan13 .wintersecurity .util ;
17+ package io .wwan13 .wintersecurity .resolve . util ;
1818
1919import com .fasterxml .jackson .databind .DeserializationFeature ;
2020import com .fasterxml .jackson .databind .ObjectMapper ;
2121
22- public class TypeConverter {
22+ public class ResolveTypeConverter {
2323
2424 private static final ObjectMapper objectMapper = new ObjectMapper ()
2525 .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
26+ private static final String ERROR_MESSAGE_FORMAT =
27+ "'%s' cannot be converted to declared type '%s'" ;
2628
27- private TypeConverter () {
29+ private ResolveTypeConverter () {
2830 throw new IllegalStateException ("Cannot instantiate a utility class!" );
2931 }
3032
3133 public static Object convertTo (Object originValue , Class <?> targetClazz ) {
32- return objectMapper .convertValue (originValue , targetClazz );
34+ try {
35+ return objectMapper .convertValue (originValue , targetClazz );
36+ } catch (IllegalArgumentException e ) {
37+ throw new IllegalStateException (
38+ String .format (ERROR_MESSAGE_FORMAT , originValue , targetClazz .getSimpleName ())
39+ );
40+ }
3341 }
3442}
You can’t perform that action at this time.
0 commit comments