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

temporalio / sdk-java / #341

24 Oct 2024 04:18PM UTC coverage: 78.746% (+0.04%) from 78.708%
#341

push

github

web-flow
Add failure_reason to nexus_task_execution_failed (#2274)

Add failure_reason to nexus_task_execution_failed

22 of 26 new or added lines in 2 files covered. (84.62%)

48 existing lines in 7 files now uncovered.

22726 of 28860 relevant lines covered (78.75%)

0.79 hits per line

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

81.25
/temporal-sdk/src/main/java/io/temporal/internal/nexus/PayloadSerializer.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.internal.nexus;
22

23
import com.google.protobuf.InvalidProtocolBufferException;
24
import io.nexusrpc.Serializer;
25
import io.temporal.api.common.v1.Payload;
26
import io.temporal.common.converter.DataConverter;
27
import java.lang.reflect.ParameterizedType;
28
import java.lang.reflect.Type;
29
import java.util.Optional;
30
import javax.annotation.Nullable;
31

32
/**
33
 * PayloadSerializer is a serializer that converts objects to and from {@link
34
 * io.nexusrpc.Serializer.Content} objects by using the {@link DataConverter} to convert objects to
35
 * and from {@link Payload} objects.
36
 */
37
class PayloadSerializer implements Serializer {
38
  DataConverter dataConverter;
39

40
  PayloadSerializer(DataConverter dataConverter) {
1✔
41
    this.dataConverter = dataConverter;
1✔
42
  }
1✔
43

44
  @Override
45
  public Content serialize(@Nullable Object o) {
46
    Optional<Payload> payload = dataConverter.toPayload(o);
1✔
47
    Content.Builder content = Content.newBuilder();
1✔
48
    content.setData(payload.get().toByteArray());
1✔
49
    return content.build();
1✔
50
  }
51

52
  @Override
53
  public @Nullable Object deserialize(Content content, Type type) {
54
    try {
55
      Payload payload = Payload.parseFrom(content.getData());
1✔
56
      if ((type instanceof Class)) {
1✔
57
        return dataConverter.fromPayload(payload, (Class<?>) type, type);
1✔
58
      } else if (type instanceof ParameterizedType) {
1✔
59
        return dataConverter.fromPayload(
1✔
60
            payload, (Class<?>) ((ParameterizedType) type).getRawType(), type);
1✔
61
      } else {
UNCOV
62
        throw new IllegalArgumentException("Unsupported type: " + type);
×
63
      }
UNCOV
64
    } catch (InvalidProtocolBufferException e) {
×
UNCOV
65
      throw new RuntimeException(e);
×
66
    }
67
  }
68
}
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