-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1125: Add
FailedDeserializationInfo
Fixes #1125 Main ideas: * It does not enforces one single function to be set, it simply makes the new one to take precedence. * When setting the function/supplier via configuration, one single configuration key/value pair is enough. It tries to fit in any of the two possible options, otherwise, raises errors. * I'd personally rename `private BiFunction<byte[], Headers, T> failedDeserializationFunction;` to `failedDeserializationBiFunction`, respecting the name at setter level. However i read about avoiding sugar refactoring as rule of thumb. * Simplify and unify setFailedDeserializationFunction & recoverFromSupplier methods from ErrorHandlingDeserializer2 * deprecated since was in the wrong place * Javadocs for ErrorHandlingDeserializer2 and adocs syntax's amends. * Correct FailedDeserializationInfo & ErrorHandlingDeserializer2 copyright years * Correct FailedDeserializationInfo this invocation & ErrorHandlingDeserializer2 java docs headers *Polishing code style **Cherry-pick to 2.2.x** # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/support/serializer/ErrorHandlingDeserializer2.java # src/reference/asciidoc/whats-new.adoc
- Loading branch information
1 parent
020dfc9
commit 5fae3a9
Showing
4 changed files
with
151 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...src/main/java/org/springframework/kafka/support/serializer/FailedDeserializationInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.kafka.support.serializer; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.kafka.common.header.Headers; | ||
|
||
/** | ||
* Class containing all the contextual information around a deserialization error. | ||
* | ||
* @author Victor Perez Rey | ||
* | ||
* @since 2.2.8 | ||
*/ | ||
public class FailedDeserializationInfo { | ||
|
||
private final String topic; | ||
|
||
private final Headers headers; | ||
|
||
private final byte[] data; | ||
|
||
private final boolean isForKey; | ||
|
||
private final Exception exception; | ||
|
||
/** | ||
* Construct an instance with the contextual information. | ||
* @param topic topic associated with the data. | ||
* @param headers headers associated with the record; may be empty. | ||
* @param data serialized bytes; may be null. | ||
* @param isForKey true for a key deserializer, false otherwise. | ||
* @param exception exception causing the deserialization error. | ||
*/ | ||
public FailedDeserializationInfo(String topic, Headers headers, byte[] data, boolean isForKey, | ||
Exception exception) { | ||
|
||
this.topic = topic; | ||
this.headers = headers; | ||
this.data = data; | ||
this.isForKey = isForKey; | ||
this.exception = exception; | ||
} | ||
|
||
public String getTopic() { | ||
return this.topic; | ||
} | ||
|
||
public Headers getHeaders() { | ||
return this.headers; | ||
} | ||
|
||
public byte[] getData() { | ||
return this.data; | ||
} | ||
|
||
public boolean isForKey() { | ||
return this.isForKey; | ||
} | ||
|
||
public Exception getException() { | ||
return this.exception; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FailedDeserializationInfo{" + | ||
"topic='" + this.topic + '\'' + | ||
", headers=" + this.headers + | ||
", data=" + Arrays.toString(this.data) + | ||
", isForKey=" + this.isForKey + | ||
", exception=" + this.exception + | ||
'}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters