1919import com .fasterxml .jackson .core .JsonParser ;
2020import com .fasterxml .jackson .core .JsonToken ;
2121import com .fasterxml .jackson .databind .DeserializationContext ;
22+ import com .fasterxml .jackson .databind .JsonMappingException ;
2223import com .fasterxml .jackson .databind .deser .std .StdScalarDeserializer ;
24+ import com .google .errorprone .annotations .CompileTimeConstant ;
25+ import com .palantir .logsafe .Arg ;
26+ import com .palantir .logsafe .SafeLoggable ;
2327import java .io .IOException ;
2428import java .nio .file .Path ;
2529import java .nio .file .Paths ;
30+ import java .util .List ;
2631
2732public final class PathDeserializer extends StdScalarDeserializer <Path > {
2833 private static final long serialVersionUID = 1 ;
@@ -40,6 +45,26 @@ public Path deserialize(JsonParser parser, DeserializationContext ctxt) throws I
4045 }
4146 // 16-Oct-2015: should we perhaps allow JSON Arrays (of Strings) as well?
4247 }
43- throw ctxt .mappingException (Path .class , token );
48+ throw new SafeJsonMappingException (
49+ "Could not deserialize path" , parser , ctxt .wrongTokenException (parser , Path .class , token , null ));
50+ }
51+
52+ private static final class SafeJsonMappingException extends JsonMappingException implements SafeLoggable {
53+ private final String logMessage ;
54+
55+ SafeJsonMappingException (@ CompileTimeConstant String message , JsonParser parser , JsonMappingException cause ) {
56+ super (parser , message , cause );
57+ this .logMessage = message ;
58+ }
59+
60+ @ Override
61+ public String getLogMessage () {
62+ return logMessage ;
63+ }
64+
65+ @ Override
66+ public List <Arg <?>> getArgs () {
67+ return List .of ();
68+ }
4469 }
4570}
0 commit comments