Skip to content

Commit 76e2f18

Browse files
committed
Pass a JSONObject instead of a Map in the constructor. Save 'json' to return as String.
1 parent 4756322 commit 76e2f18

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/main/java/io/ipgeolocation/api/GeolocationCurrency.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
package io.ipgeolocation.api;
22

3-
import java.util.Map;
3+
import java.util.Objects;
4+
import org.json.JSONObject;
45

56
public class GeolocationCurrency {
67
private final String name;
78
private final String code;
89
private final String symbol;
10+
private final JSONObject json;
911

10-
GeolocationCurrency(Map<String, Object> json) {
11-
this.name = (String) json.get("name");
12-
this.code = (String) json.get("code");
13-
this.symbol = (String) json.get("symbol");
12+
GeolocationCurrency(JSONObject json) {
13+
if (Objects.isNull(json)) {
14+
throw new IllegalArgumentException("'json' must not be null");
15+
}
16+
17+
if (json.isEmpty()) {
18+
throw new IllegalArgumentException("'json' must not be empty");
19+
}
20+
21+
this.name = json.getString("name");
22+
this.code = json.getString("code");
23+
this.symbol = json.getString("symbol");
24+
this.json = json;
1425
}
1526

1627
public String getName() {
@@ -24,4 +35,9 @@ public String getCode() {
2435
public String getSymbol() {
2536
return symbol;
2637
}
38+
39+
@Override
40+
public String toString() {
41+
return json.toString(2);
42+
}
2743
}

0 commit comments

Comments
 (0)