Skip to content

Commit

Permalink
Replace deprecated mappingException (#2714)
Browse files Browse the repository at this point in the history
Replace deprecated mappingException
  • Loading branch information
schlosna authored Oct 21, 2023
1 parent a0732a7 commit 2de466e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2714.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Replace deprecated mappingException
links:
- https://github.com/palantir/conjure-java-runtime/pull/2714
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.SafeLoggable;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public final class PathDeserializer extends StdScalarDeserializer<Path> {
private static final long serialVersionUID = 1;
Expand All @@ -58,6 +63,26 @@ public Path deserialize(JsonParser parser, DeserializationContext ctxt) throws I
}
// 16-Oct-2015: should we perhaps allow JSON Arrays (of Strings) as well?
}
throw ctxt.mappingException(Path.class, token);
throw new SafeJsonMappingException(
"Could not deserialize path", parser, ctxt.wrongTokenException(parser, Path.class, token, null));
}

private static final class SafeJsonMappingException extends JsonMappingException implements SafeLoggable {
private final String logMessage;

SafeJsonMappingException(@CompileTimeConstant String message, JsonParser parser, JsonMappingException cause) {
super(parser, message, cause);
this.logMessage = message;
}

@Override
public String getLogMessage() {
return logMessage;
}

@Override
public List<Arg<?>> getArgs() {
return List.of();
}
}
}

0 comments on commit 2de466e

Please sign in to comment.