@@ -32,6 +32,8 @@ public class Index implements Serializable {
32
32
@ ToString .Exclude
33
33
Documents documents ;
34
34
35
+ Gson gson = new Gson ();
36
+
35
37
/**
36
38
* Set the Meilisearch configuration for the index
37
39
*
@@ -124,8 +126,11 @@ public String search(String q) throws Exception {
124
126
* @return Meilisearch API response
125
127
* @throws Exception If something goes wrong
126
128
*/
127
- public String getUpdate (int updateId ) throws Exception {
128
- return this .documents .getUpdate (this .uid , updateId );
129
+ public UpdateStatus getUpdate (int updateId ) throws Exception {
130
+ return this .gson .fromJson (
131
+ this .documents .getUpdate (this .uid , updateId ),
132
+ UpdateStatus .class
133
+ );
129
134
}
130
135
131
136
/**
@@ -135,8 +140,10 @@ public String getUpdate(int updateId) throws Exception {
135
140
* @throws Exception If something goes wrong
136
141
*/
137
142
public UpdateStatus [] getUpdates () throws Exception {
138
- Gson gson = new Gson ();
139
- return gson .fromJson (this .documents .getUpdates (this .uid ), UpdateStatus [].class );
143
+ return this .gson .fromJson (
144
+ this .documents .getUpdates (this .uid ),
145
+ UpdateStatus [].class
146
+ );
140
147
}
141
148
142
149
/**
@@ -160,7 +167,6 @@ public void waitForPendingUpdate(int updateId) throws Exception {
160
167
* @throws Exception if timeout is reached
161
168
*/
162
169
public void waitForPendingUpdate (int updateId , int timeoutInMs , int intervalInMs ) throws Exception {
163
- Gson gson = new Gson ();
164
170
UpdateStatus updateStatus ;
165
171
String status = "" ;
166
172
long startTime = new Date ().getTime ();
@@ -170,10 +176,7 @@ public void waitForPendingUpdate(int updateId, int timeoutInMs, int intervalInMs
170
176
if (elapsedTime >= timeoutInMs ){
171
177
throw new Exception ();
172
178
}
173
- updateStatus = gson .fromJson (
174
- this .getUpdate (updateId ),
175
- UpdateStatus .class
176
- );
179
+ updateStatus = this .getUpdate (updateId );
177
180
status = updateStatus .getStatus ();
178
181
Thread .sleep (intervalInMs );
179
182
elapsedTime = new Date ().getTime () - startTime ;
0 commit comments