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

smartsheet / smartsheet-java-sdk / #60

24 Oct 2025 09:43AM UTC coverage: 60.156% (+0.4%) from 59.737%
#60

push

github

web-flow
Add Wiremock integration tests and update dependencies (#145)

* Add Wiremock integration tests and update dependencies

* Update test method names

* Bump version to 3.9.0 and address comments for the wiremock integration tests

* Refactor Wiremock integration tests for user resources to improve query parameter handling and update endpoint paths

* Fix imports

* Fix checkstyle errors

* Move wiremock tests to sdktest

* Remove redundant Wiremock tests from UserResourcesIT

* Remove unused imports from UserResourcesIT

* Revert UserResourcesIT

* Fix changelog

* Add copyright to WiremockTest

* Update wiremock base uri port

* Rename WiremockTest to UserResourcesContractTests for clarity

* Change WireMock default port

4392 of 7301 relevant lines covered (60.16%)

0.6 hits per line

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

57.14
/src/main/java/com/smartsheet/api/internal/json/ObjectValueDeserializer.java
1
/*
2
 * Copyright (C) 2025 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.JsonProcessingException;
21
import com.fasterxml.jackson.core.JsonToken;
22
import com.fasterxml.jackson.databind.DeserializationContext;
23
import com.fasterxml.jackson.databind.DeserializationFeature;
24
import com.fasterxml.jackson.databind.JsonDeserializer;
25
import com.fasterxml.jackson.databind.ObjectMapper;
26
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
27
import com.smartsheet.api.models.BooleanObjectValue;
28
import com.smartsheet.api.models.ContactObjectValue;
29
import com.smartsheet.api.models.DateObjectValue;
30
import com.smartsheet.api.models.Duration;
31
import com.smartsheet.api.models.MultiContactObjectValue;
32
import com.smartsheet.api.models.MultiPicklistObjectValue;
33
import com.smartsheet.api.models.NumberObjectValue;
34
import com.smartsheet.api.models.ObjectValue;
35
import com.smartsheet.api.models.Predecessor;
36
import com.smartsheet.api.models.PredecessorList;
37
import com.smartsheet.api.models.StringObjectValue;
38
import com.smartsheet.api.models.enums.ObjectValueType;
39

40
import java.io.IOException;
41
import java.util.ArrayList;
42
import java.util.List;
43

44
public class ObjectValueDeserializer extends JsonDeserializer<ObjectValue> {
1✔
45

46
    @Override
47
    public ObjectValue deserialize(JsonParser jp, DeserializationContext ctxt)
48
            throws IOException, JsonProcessingException {
49

50
        final ObjectValue objectValue;
51
        ContactObjectValue contactObjectValue = null;
1✔
52

53
        if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
1✔
54
            ObjectMapper mapper = new ObjectMapper();
1✔
55
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1✔
56

57
            ObjectValueAttributeSuperset superset = mapper.readValue(jp, ObjectValueAttributeSuperset.class);
1✔
58
            mapper.registerModule(new JavaTimeModule());
1✔
59

60
            ObjectValueType parsedObjectType;
61
            try {
62
                parsedObjectType = ObjectValueType.valueOf(superset.objectType);
1✔
63
            } catch (IllegalArgumentException e) {
1✔
64
                // If a new object type is introduced to the Smartsheet API that this version of the SDK doesn't support,
65
                // return null instead of throwing an exception.
66
                return null;
1✔
67
            }
1✔
68

69
            switch (parsedObjectType) {
1✔
70
                case DURATION:
71
                    objectValue = new Duration(
1✔
72
                            superset.negative,
73
                            superset.elapsed,
74
                            superset.weeks,
75
                            superset.days,
76
                            superset.hours,
77
                            superset.minutes,
78
                            superset.seconds,
79
                            superset.milliseconds);
80
                    break;
1✔
81

82
                case PREDECESSOR_LIST:
83
                    objectValue = new PredecessorList(superset.predecessors);
×
84
                    break;
×
85

86
                case CONTACT:
87
                    contactObjectValue = new ContactObjectValue();
×
88
                    contactObjectValue.setName(superset.name);
×
89
                    contactObjectValue.setEmail(superset.email);
×
90
                    contactObjectValue.setId(superset.id);
×
91
                    objectValue = contactObjectValue;
×
92
                    break;
×
93

94
                case DATE:
95
                    // Intentional fallthrough
96
                case DATETIME:
97
                    // Intentional fallthrough
98
                case ABSTRACT_DATETIME:
99
                    objectValue = new DateObjectValue(parsedObjectType, superset.value);
1✔
100
                    break;
1✔
101

102
                case MULTI_CONTACT:
103
                    List<ContactObjectValue> contactObjectValues = new ArrayList<>();
×
104
                    for (Object contact : superset.values) {
×
105
                        contactObjectValue = mapper.convertValue(contact, ContactObjectValue.class);
×
106
                        contactObjectValues.add(contactObjectValue);
×
107
                    }
×
108
                    objectValue = new MultiContactObjectValue(contactObjectValues);
×
109
                    break;
×
110

111
                case MULTI_PICKLIST:
112
                    objectValue = new MultiPicklistObjectValue((List<String>) superset.values);
×
113
                    break;
×
114

115
                default:
116
                    objectValue = null;
×
117
            }
118
        } else {
1✔
119
            JsonToken token = jp.getCurrentToken();
1✔
120
            if (token.isBoolean()) {
1✔
121
                objectValue = new BooleanObjectValue(jp.getBooleanValue());
1✔
122
            } else if (token.isNumeric()) {
1✔
123
                objectValue = new NumberObjectValue(jp.getNumberValue());
1✔
124
            } else {
125
                objectValue = new StringObjectValue(jp.getText());
1✔
126
            }
127
        }
128
        return objectValue;
1✔
129
    }
130

131
    private static class ObjectValueAttributeSuperset {
132
        // This needs to be represented as a string so that any new object types added won't completely break the API
133
        public String objectType;
134

135
        // PREDECESSOR_LIST specific attributes
136
        public List<Predecessor> predecessors;
137

138
        // DURATION specific attributes
139
        public Boolean negative;
140
        public Boolean elapsed;
141
        public Double weeks;
142
        public Double days;
143
        public Double hours;
144
        public Double minutes;
145
        public Double seconds;
146
        public Double milliseconds;
147

148
        // CONTACT specific attributes
149
        public String id;
150
        public String name;
151
        public String email;
152

153
        // MULTI_CONTACT
154
        public List<?> values;
155

156
        // Various other types
157
        public String value;
158
    }
159
}
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