Skip to content

Commit b88e921

Browse files
committed
Simplify Config class
1 parent 23e186a commit b88e921

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,14 @@ The default JSON library is `Gson`. You can however use another library with the
231231

232232
#### Using `JacksonJsonHandler` <!-- omit in toc -->
233233

234-
Set up your client by initializing `Config` with a new `JacksonJsonHandler` object.
234+
Initialize your `Config` and assign it a new `JacksonJsonHandler` object as `JsonHandler`.
235+
Set up your `Client` with it.
235236

236237
```java
237238
import com.meilisearch.sdk.json.JacksonJsonHandler;
238239

239-
Config config = new Config("http://localhost:7700", "masterKey", new JacksonJsonHandler());
240+
Config config = new Config("http://localhost:7700", "masterKey");
241+
config.setJsonHandler(new JacksonJsonHandler());
240242
Client client = new Client(config);
241243
```
242244

@@ -253,7 +255,8 @@ To create your own JSON handler, you must conform to the `JsonHandler` interface
253255
Then create your client by initializing your `Config` with your new handler.
254256

255257
```java
256-
Config config = new Config("http://localhost:7700", "masterKey", new myJsonHandler());
258+
Config config = new Config("http://localhost:7700", "masterKey");
259+
config.setJsonHandler(new myJsonHandler());
257260
Client client = new Client(config);
258261
```
259262

src/main/java/com/meilisearch/sdk/Config.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,24 @@
33
import com.meilisearch.sdk.json.GsonJsonHandler;
44
import com.meilisearch.sdk.json.JsonHandler;
55
import lombok.Getter;
6+
import lombok.Setter;
67

78
/** Meilisearch configuration */
89
@Getter
10+
@Setter
911
public class Config {
1012
protected final String hostUrl;
1113
protected final String apiKey;
12-
protected final JsonHandler jsonHandler;
1314
protected final HttpClient httpClient;
15+
protected JsonHandler jsonHandler;
1416

1517
/**
1618
* Creates a configuration without an API key
1719
*
1820
* @param hostUrl URL of the Meilisearch instance
1921
*/
2022
public Config(String hostUrl) {
21-
this(hostUrl, "", new GsonJsonHandler());
22-
}
23-
24-
/**
25-
* Creates a configuration without an API key and with a JsonHandler
26-
*
27-
* @param hostUrl URL of the Meilisearch instance
28-
* @param jsonHandler Json handler to serialize and deserialize Java objects to JSON
29-
*/
30-
public Config(String hostUrl, JsonHandler jsonHandler) {
31-
this.hostUrl = hostUrl;
32-
this.apiKey = "";
33-
this.jsonHandler = jsonHandler;
34-
this.httpClient = new HttpClient(this);
23+
this(hostUrl, "");
3524
}
3625

3726
/**
@@ -47,20 +36,6 @@ public Config(String hostUrl, String apiKey) {
4736
this.httpClient = new HttpClient(this);
4837
}
4938

50-
/**
51-
* Creates a configuration with an API key and a JsonHandler
52-
*
53-
* @param hostUrl URL of the Meilisearch instance
54-
* @param apiKey API key to pass to the header of requests sent to Meilisearch
55-
* @param jsonHandler Json handler to serialize and deserialize Java objects to JSON
56-
*/
57-
public Config(String hostUrl, String apiKey, JsonHandler jsonHandler) {
58-
this.hostUrl = hostUrl;
59-
this.apiKey = apiKey;
60-
this.jsonHandler = jsonHandler;
61-
this.httpClient = new HttpClient(this);
62-
}
63-
6439
/**
6540
* Method for returning the concatenated Bearer header with apiKey
6641
*

src/main/java/com/meilisearch/sdk/SearchRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ private SearchRequest(
333333
* <p>This method is an alias of setQ()
334334
*
335335
* @param q Query String
336+
* @return SearchRequest
336337
*/
337338
public SearchRequest setQuery(String q) {
338339
return setQ(q);

src/test/java/com/meilisearch/integration/classes/AbstractIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ public void setUp() {
4141
}
4242

4343
public void setUpJacksonClient() {
44-
if (clientJackson == null)
45-
clientJackson =
46-
new Client(
47-
new Config(
48-
getMeilisearchHost(), "masterKey", new JacksonJsonHandler()));
44+
Config config = new Config(getMeilisearchHost(), "masterKey");
45+
config.setJsonHandler(new JacksonJsonHandler());
46+
if (client == null) client = new Client(config);
4947
}
5048

5149
public static void cleanup() {

0 commit comments

Comments
 (0)