-
Notifications
You must be signed in to change notification settings - Fork 16
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
Deserialize endpoint errors #2443
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
...c/test/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorsConjureBodySerDeTest.java
Outdated
Show resolved
Hide resolved
...c/test/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorsConjureBodySerDeTest.java
Outdated
Show resolved
Hide resolved
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDe.java
Outdated
Show resolved
Hide resolved
6081541
to
74008d5
Compare
74008d5
to
a46dd8b
Compare
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDe.java
Outdated
Show resolved
Hide resolved
a46dd8b
to
c6dfe0c
Compare
dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDeTest.java
Outdated
Show resolved
Hide resolved
dialogue-annotations/src/main/java/com/palantir/dialogue/annotations/ConjureErrorDecoder.java
Outdated
Show resolved
Hide resolved
c6dfe0c
to
487b4ff
Compare
eb93b54
to
3b2987f
Compare
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java
Show resolved
Hide resolved
3ae5194
to
a665dbf
Compare
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDe.java
Outdated
Show resolved
Hide resolved
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDe.java
Outdated
Show resolved
Hide resolved
a665dbf
to
5221bb9
Compare
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDe.java
Show resolved
Hide resolved
dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java
Outdated
Show resolved
Hide resolved
dialogue-target/src/main/java/com/palantir/dialogue/DeserializerArgs.java
Outdated
Show resolved
Hide resolved
dialogue-target/src/main/java/com/palantir/dialogue/DeserializerArgs.java
Outdated
Show resolved
Hide resolved
dialogue-target/src/main/java/com/palantir/dialogue/DeserializerArgs.java
Outdated
Show resolved
Hide resolved
dialogue-target/src/main/java/com/palantir/dialogue/DeserializerArgs.java
Outdated
Show resolved
Hide resolved
dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ErrorDecoderTest.java
Outdated
Show resolved
Hide resolved
6012f80
to
32885e2
Compare
String jsonContentType = "application/json"; | ||
if (contentType.isPresent() && Encodings.matchesContentType(jsonContentType, contentType.get())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we update this to leverage the Encoding
with something along these lines?
Encodings.matchesContentType(JSON_ENCODING.getContentType(), contentType.get())
If it's not terribly troublesome, we may want to take the existing json encoding from the configured set of encodings when it's present, and create a new one as a fallback. This way if the client is configured with encodings wrapped to produce metrics/etc, we can retain that functionality.
JsonNode node = MAPPER.readTree(body); | ||
JsonNode errorNameNode = node.get("errorName"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written we're fully transforming the input json into a JsonNode tree, and reading at most a single string element.
We can define something like this to allow jackson to extract only the pieces of data we're interested in:
private record NamedError(@JsonProperty("errorName") String errorName) {}
32885e2
to
4ef5fe8
Compare
4ef5fe8
to
7dac6ee
Compare
try (Reader reader = new InputStreamReader(body, StandardCharsets.UTF_8)) { | ||
return CharStreams.toString(reader).getBytes(StandardCharsets.UTF_8); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to convert the bytestream into a charstream (reader) to then convert back again in the other direction!
try (Reader reader = new InputStreamReader(body, StandardCharsets.UTF_8)) { | |
return CharStreams.toString(reader).getBytes(StandardCharsets.UTF_8); | |
} | |
try (body) { | |
return body.readAllBytes(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 This was dumb. Fixed.
SerializableError serializableError = JSON_ENCODING | ||
.deserializer(new TypeMarker<SerializableError>() {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we initialize this Deserializer<SerializableError>
once above, rather than creating it anew each time it's needed?
Maps.transformValues(errorNameToTypeMap, maybeJsonEncoding.orElse(JSON_ENCODING)::deserializer)); | ||
} | ||
|
||
public boolean isError(Response response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove public
from all the utility methods here, since the class itself is package private
fad1f82
to
c67cb58
Compare
Looks solid -- want to start on the codegen piece using an RC? |
Yep. Added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to cut an RC for iteration with conjure-java codegen 👍
[skip ci]
Invalidated by push of ae9dfff
Before this PR
We'd like to support the a new method in
BodySerDe
that allows the creation of deserializers given an expected result type, and a set of expected error types.A ConjureError is serialized and sent by servers. Dialogue deserializes the errors to a
SerializableError
which loses the type information of the parameters. By providing the type information of the parameters, Dialogue can deserialize the receivedConjureError
into the well-typed objects (instead of Strings).After this PR
==COMMIT_MSG==
==COMMIT_MSG==
Possible downsides?