Skip to content

Commit b5d599f

Browse files
committed
refactor : Modified to throw IllegalStateException after modifying to Resolver-only utility class
1 parent af55a1a commit b5d599f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/io/wwan13/wintersecurity/util/TypeConverter.java renamed to src/main/java/io/wwan13/wintersecurity/resolve/util/ResolveTypeConverter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.wwan13.wintersecurity.util;
17+
package io.wwan13.wintersecurity.resolve.util;
1818

1919
import com.fasterxml.jackson.databind.DeserializationFeature;
2020
import 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
}

0 commit comments

Comments
 (0)