Skip to content

Commit 9ad61ac

Browse files
committed
chore(deps): remove javax and replacing it by jackson
1 parent 0c13460 commit 9ad61ac

3 files changed

Lines changed: 145 additions & 180 deletions

File tree

pom.xml

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,16 @@
3535
</scm>
3636

3737
<dependencies>
38-
<dependency>
39-
<groupId>com.fasterxml.jackson.core</groupId>
40-
<artifactId>jackson-databind</artifactId>
41-
<version>${jackson.databind.version}</version>
42-
</dependency>
4338
<dependency>
4439
<groupId>io.apimatic</groupId>
4540
<artifactId>core-interfaces</artifactId>
4641
<version>[0.3, 0.4)</version>
4742
</dependency>
48-
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
51-
<version>4.13.2</version>
52-
<scope>test</scope>
53-
</dependency>
54-
<dependency>
55-
<groupId>javax.xml.bind</groupId>
56-
<artifactId>jaxb-api</artifactId>
57-
<version>2.4.0-b180830.0359</version>
58-
</dependency>
59-
<dependency>
60-
<groupId>org.glassfish.jaxb</groupId>
61-
<artifactId>jaxb-runtime</artifactId>
62-
<version>2.3.2</version>
63-
</dependency>
64-
<dependency>
65-
<groupId>org.mockito</groupId>
66-
<artifactId>mockito-core</artifactId>
67-
<version>4.11.0</version>
68-
<scope>test</scope>
69-
</dependency>
70-
<dependency>
71-
<groupId>org.mockito</groupId>
72-
<artifactId>mockito-inline</artifactId>
73-
<version>4.11.0</version>
74-
<scope>test</scope>
75-
</dependency>
43+
<dependency>
44+
<groupId>com.fasterxml.jackson.core</groupId>
45+
<artifactId>jackson-databind</artifactId>
46+
<version>${jackson.databind.version}</version>
47+
</dependency>
7648
<dependency>
7749
<groupId>com.fasterxml.jackson.core</groupId>
7850
<artifactId>jackson-core</artifactId>
@@ -88,17 +60,30 @@
8860
<artifactId>slf4j-api</artifactId>
8961
<version>2.0.10</version>
9062
</dependency>
91-
<dependency>
92-
<groupId>org.jacoco</groupId>
93-
<artifactId>jacoco-maven-plugin</artifactId>
94-
<version>0.8.10</version>
95-
<scope>test</scope>
96-
</dependency>
97-
<dependency>
98-
<groupId>org.glassfish</groupId>
99-
<artifactId>javax.json</artifactId>
100-
<version>1.1.4</version>
101-
</dependency>
63+
<dependency>
64+
<groupId>junit</groupId>
65+
<artifactId>junit</artifactId>
66+
<version>4.13.2</version>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.jacoco</groupId>
71+
<artifactId>jacoco-maven-plugin</artifactId>
72+
<version>0.8.10</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.mockito</groupId>
77+
<artifactId>mockito-core</artifactId>
78+
<version>4.11.0</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.mockito</groupId>
83+
<artifactId>mockito-inline</artifactId>
84+
<version>4.11.0</version>
85+
<scope>test</scope>
86+
</dependency>
10287
</dependencies>
10388

10489
<build>

src/main/java/io/apimatic/core/ErrorCase.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import java.util.regex.Matcher;
44
import java.util.regex.Pattern;
5-
import javax.json.Json;
6-
import javax.json.JsonException;
7-
import javax.json.JsonPointer;
8-
import javax.json.JsonStructure;
95
import io.apimatic.core.types.CoreApiException;
106
import io.apimatic.core.utilities.CoreHelper;
117
import io.apimatic.coreinterfaces.http.Context;
@@ -139,48 +135,41 @@ private String replaceHeadersFromTemplate(HttpHeaders headers, String reason) {
139135

140136
private String replaceBodyFromTemplate(String responseBody, String reason) {
141137
StringBuilder formatter = new StringBuilder(reason);
142-
JsonStructure jsonStructure = CoreHelper.createJsonStructure(responseBody);
143138
Matcher matcher = Pattern.compile("\\{(.*?)\\}").matcher(reason);
144139
while (matcher.find()) {
145140
String key = matcher.group(1);
146141
String pointerKey = key;
147-
replaceBodyString(responseBody, formatter, jsonStructure, key, pointerKey);
142+
replaceBodyString(responseBody, formatter, key, pointerKey);
148143
}
149144
return formatter.toString().replace("\"", "");
150145
}
151146

152147
private void replaceBodyString(String responseBody, StringBuilder formatter,
153-
JsonStructure jsonStructure, String key, String pointerKey) {
148+
String key, String pointerKey) {
154149
if (pointerKey.startsWith("$response.body")) {
155150
String formatKey = String.format("{%s}", key);
156151
int index = formatter.indexOf(formatKey);
157-
String toReplaceString = "";
158-
toReplaceString = extractReplacementString(responseBody, jsonStructure, pointerKey,
159-
toReplaceString);
160152
if (index != -1) {
161-
try {
162-
163-
formatter.replace(index, index + formatKey.length(), toReplaceString);
164-
} catch (JsonException ex) {
165-
formatter.replace(index, index + formatKey.length(), "");
166-
}
153+
String toReplaceString = extractReplacementString(responseBody, pointerKey);
154+
formatter.replace(index, index + formatKey.length(), toReplaceString);
167155
}
168156
}
169157
}
170158

171-
private String extractReplacementString(String responseBody, JsonStructure jsonStructure,
172-
String pointerKey, String toReplaceString) {
159+
private String extractReplacementString(String responseBody, String pointerKey) {
173160
if (pointerKey.contains("#")) {
174161
pointerKey = pointerKey.replace("$response.body#", "");
175-
JsonPointer jsonPointer = Json.createPointer(pointerKey);
176-
if (jsonStructure != null && jsonPointer.containsValue(jsonStructure)) {
177-
toReplaceString = jsonPointer.getValue(jsonStructure).toString();
178-
}
179-
} else {
180-
if (responseBody != null && !responseBody.isEmpty()) {
181-
toReplaceString = responseBody;
162+
String pointerValue = CoreHelper.getValueFromJson(pointerKey, responseBody);
163+
if (pointerValue != null) {
164+
return pointerValue;
182165
}
166+
return "";
183167
}
184-
return toReplaceString;
168+
169+
if (responseBody != null && !responseBody.isEmpty()) {
170+
return responseBody;
171+
}
172+
173+
return "";
185174
}
186175
}

0 commit comments

Comments
 (0)