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

smartsheet / smartsheet-java-sdk / #55

02 Oct 2024 07:40PM UTC coverage: 60.548% (+0.7%) from 59.836%
#55

push

github

web-flow
Release prep for 3.2.1 (#103)

4156 of 6864 relevant lines covered (60.55%)

0.61 hits per line

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

66.67
/src/main/java/com/smartsheet/api/internal/json/ErrorDeserializer.java
1
/*
2
 * Copyright (C) 2024 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api.internal.json;
18

19
import com.fasterxml.jackson.core.JsonParser;
20
import com.fasterxml.jackson.core.JsonToken;
21
import com.fasterxml.jackson.core.type.TypeReference;
22
import com.fasterxml.jackson.databind.DeserializationContext;
23
import com.fasterxml.jackson.databind.JsonDeserializer;
24
import com.fasterxml.jackson.databind.JsonNode;
25
import com.fasterxml.jackson.databind.ObjectMapper;
26
import com.smartsheet.api.models.ErrorDetail;
27

28
import java.io.IOException;
29
import java.util.List;
30

31
public class ErrorDeserializer extends JsonDeserializer<com.smartsheet.api.models.Error> {
1✔
32

33
    @Override
34
    public com.smartsheet.api.models.Error deserialize(JsonParser jp, DeserializationContext ctxt)
35
            throws IOException {
36

37
        ObjectMapper mapper = new ObjectMapper();
1✔
38

39
        final com.smartsheet.api.models.Error error = new com.smartsheet.api.models.Error();
1✔
40

41
        if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
1✔
42
            JsonNode node = jp.getCodec().readTree(jp);
1✔
43
            if (node.get("errorCode") != null) {
1✔
44
                error.setErrorCode(node.get("errorCode").asInt());
1✔
45
            }
46
            if (node.get("message") != null) {
1✔
47
                error.setMessage(node.get("message").asText());
1✔
48
            }
49
            if (node.get("refId") != null) {
1✔
50
                error.setRefId(node.get("refId").asText());
1✔
51
            }
52
            JsonNode detail = node.get("detail");
1✔
53
            if (detail != null) {
1✔
54
                if (detail.isArray()) {
×
55
                    String asText = detail.toString();
×
56
                    List<ErrorDetail> details = mapper.readValue(asText, new TypeReference<List<ErrorDetail>>() {
×
57
                    });
58
                    error.setDetail(details);
×
59
                } else {
×
60
                    error.setDetail(mapper.treeToValue(detail, ErrorDetail.class));
×
61
                }
62
            }
63
            return error;
1✔
64
        }
65
        return null;
×
66
    }
67
}
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