Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated mappingException #2714

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}