• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #156

pending completion
#156

push

github-actions

web-flow
Provide SerializationContext for PayloadConverter and PayloadCodec (#1695)

Issue #1694

497 of 497 new or added lines in 32 files covered. (100.0%)

16928 of 20806 relevant lines covered (81.36%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.19
/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.common.converter;
22

23
import com.google.common.base.Preconditions;
24
import java.util.*;
25
import javax.annotation.Nonnull;
26

27
/**
28
 * A {@link DataConverter} that delegates payload conversion to type specific {@link
29
 * PayloadConverter} instances, and delegates failure conversions to a {@link FailureConverter}.
30
 *
31
 * @author fateev
32
 */
33
public class DefaultDataConverter extends PayloadAndFailureDataConverter {
34

35
  // Order is important as the first converter that can convert the payload is used. Needs to match
36
  // the other SDKs. Go SDK:
37
  // https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
38
  public static final PayloadConverter[] STANDARD_PAYLOAD_CONVERTERS = {
1✔
39
    new NullPayloadConverter(),
40
    new ByteArrayPayloadConverter(),
41
    new ProtobufJsonPayloadConverter(),
42
    new ProtobufPayloadConverter(),
43
    new JacksonJsonPayloadConverter()
44
  };
45

46
  /**
47
   * Default data converter that is used for all objects if not overridden by {@link
48
   * io.temporal.client.WorkflowClientOptions.Builder#setDataConverter(DataConverter)} or {@link
49
   * GlobalDataConverter#register(DataConverter)} (less preferred).
50
   *
51
   * <p>This data converter is also always used (regardless of whether or not users have supplied
52
   * their own converter) to perform serialization of values essential for functionality of Temporal
53
   * SDK, Server, tctl or WebUI:
54
   *
55
   * <ul>
56
   *   <li>Local Activity, Version, MutableSideEffect Markers metadata like id, time, name
57
   *   <li>Search attribute values
58
   *   <li>Stacktrace query return value
59
   * </ul>
60
   */
61
  public static final DataConverter STANDARD_INSTANCE = newDefaultInstance();
1✔
62

63
  /**
64
   * @deprecated use {@link GlobalDataConverter#register(DataConverter)}
65
   */
66
  public static void setDefaultDataConverter(DataConverter converter) {
67
    GlobalDataConverter.register(converter);
×
68
  }
×
69

70
  /**
71
   * Creates a new instance of {@code DefaultDataConverter} populated with the default list of
72
   * payload converters and a default failure converter.
73
   */
74
  public static DefaultDataConverter newDefaultInstance() {
75
    return new DefaultDataConverter(STANDARD_PAYLOAD_CONVERTERS);
1✔
76
  }
77

78
  /**
79
   * Creates instance from ordered array of converters and a default failure converter. When
80
   * converting an object to payload the array of converters is iterated from the beginning until
81
   * one of the converters successfully converts the value.
82
   */
83
  public DefaultDataConverter(PayloadConverter... converters) {
84
    super(Arrays.asList(converters));
1✔
85
  }
1✔
86

87
  /**
88
   * Modifies this {@code DefaultDataConverter} by overriding some of its {@link PayloadConverter}s.
89
   * Every payload converter from {@code overrideConverters} either replaces existing payload
90
   * converter with the same encoding type, or is added to the end of payload converters list.
91
   */
92
  public DefaultDataConverter withPayloadConverterOverrides(
93
      PayloadConverter... overrideConverters) {
94
    List<PayloadConverter> newConverters = new ArrayList<>(converters);
1✔
95
    for (PayloadConverter overrideConverter : overrideConverters) {
1✔
96
      PayloadConverter existingConverter =
1✔
97
          this.convertersMap.get(overrideConverter.getEncodingType());
1✔
98
      if (existingConverter != null) {
1✔
99
        int existingConverterIndex = newConverters.indexOf(existingConverter);
1✔
100
        newConverters.set(existingConverterIndex, overrideConverter);
1✔
101
      } else {
1✔
102
        newConverters.add(overrideConverter);
×
103
      }
104
    }
105

106
    this.converters = Collections.unmodifiableList(newConverters);
1✔
107
    this.convertersMap = Collections.unmodifiableMap(createConvertersMap(converters));
1✔
108

109
    return this;
1✔
110
  }
111

112
  /**
113
   * Modifies this {@code DefaultDataConverter} by overriding its {@link FailureConverter}.
114
   *
115
   * <p>WARNING: Most users should _never_ need to override the default failure converter. To
116
   * encrypt the content of failures, see {@link CodecDataConverter} instead.
117
   *
118
   * @param failureConverter The failure converter to use
119
   * @throws NullPointerException if failureConverter is null
120
   */
121
  @Nonnull
122
  public DefaultDataConverter withFailureConverter(@Nonnull FailureConverter failureConverter) {
123
    this.failureConverter = Preconditions.checkNotNull(failureConverter, "failureConverter");
×
124
    return this;
×
125
  }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc