Skip to content

Commit f353831

Browse files
Improve PayloadConverter javadoc regarding providing of EncodingKeys#METADATA_ENCODING_KEY (#702)
Co-authored-by: Spencer Judge <sjudge@hey.com>
1 parent b077ec1 commit f353831

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

temporal-sdk/src/main/java/io/temporal/common/converter/EncodingKeys.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.google.protobuf.ByteString;
2323
import java.nio.charset.StandardCharsets;
2424

25-
class EncodingKeys {
26-
static final String METADATA_ENCODING_KEY = "encoding";
25+
public class EncodingKeys {
26+
public static final String METADATA_ENCODING_KEY = "encoding";
2727

2828
static final String METADATA_ENCODING_NULL_NAME = "binary/null";
2929
static final ByteString METADATA_ENCODING_NULL =

temporal-sdk/src/main/java/io/temporal/common/converter/PayloadConverter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package io.temporal.common.converter;
2121

22+
import com.google.protobuf.ByteString;
2223
import io.temporal.api.common.v1.Payload;
2324
import java.lang.reflect.Type;
2425
import java.util.Optional;
@@ -31,6 +32,15 @@
3132
*/
3233
public interface PayloadConverter {
3334

35+
/**
36+
* Each {@link PayloadConverter} has an Encoding Type that it handles. Each {@link
37+
* PayloadConverter} should add the information about its Encoding Type into the {@link Payload} it
38+
* produces inside {@link #toData(Object)} by associating it with the {@link
39+
* EncodingKeys#METADATA_ENCODING_KEY} key attached to the {@code Payload}'s Metadata using {@link
40+
* Payload.Builder#putMetadata(String, ByteString)}.
41+
*
42+
* @return encoding type that this converter handles.
43+
*/
3444
String getEncodingType();
3545

3646
/**
@@ -40,6 +50,7 @@ public interface PayloadConverter {
4050
* @return converted value
4151
* @throws DataConverterException if conversion of the value passed as parameter failed for any
4252
* reason.
53+
* @see #getEncodingType() getEncodingType javadoc for an important implementation detail
4354
*/
4455
Optional<Payload> toData(Object value) throws DataConverterException;
4556

temporal-sdk/src/main/java/io/temporal/internal/common/HeaderUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static Header toHeaderGrpc(
4141
}
4242

4343
/**
44-
* Converts a Map<String, Object> into a Map<String, Payload> by applying specified converter on
44+
* Converts a {@code Map<String, Object>} into a {@code Map<String, Payload>} by applying specified converter on
4545
* each value. This util should be used for things like search attributes and memo that need to be
4646
* converted back from bytes on the server.
4747
*/

temporal-sdk/src/main/java/io/temporal/workflow/Workflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public static <T> Object getMemo(String key, Class<T> valueClass) {
630630
/**
631631
* Extract Memo associated with the given key and deserialized into an object of generic type as
632632
* is done here: {@link DataConverter#fromPayloads(int, java.util.Optional, java.lang.Class,
633-
* java.lang.reflect.Type)} Ex: To deserialize into HashMap<String, Integer> <code>
633+
* java.lang.reflect.Type)} Ex: To deserialize into {@code HashMap<String, Integer>} <code>
634634
* Workflow.getMemo(key, Map.class, new TypeToken<HashMap<String, Integer>>() {}.getType());
635635
* </code>
636636
*

0 commit comments

Comments
 (0)