Skip to content

Commit 49c8dfa

Browse files
committed
feat: 1.2.1
- gradle version upgrade - Strings.equalsIgnoreCase - interfaces - JSONObject put value
1 parent 7d751fd commit 49c8dfa

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

src/main/java/com/javaquery/util/iface/Processor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* @author vicky.thakor
5-
* @since 2022-05-16
5+
* @since 1.2.1
66
*/
77
public interface Processor<T, R> {
88

src/main/java/com/javaquery/util/iface/Reader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* @author vicky.thakor
9-
* @since 2022-05-16
9+
* @since 1.2.1
1010
*/
1111
public interface Reader<T> {
1212
/**

src/main/java/com/javaquery/util/iface/Writer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* @author vicky.thakor
9-
* @since 2022-05-16
9+
* @since 1.2.1
1010
*/
1111
public interface Writer<T> {
1212
/**

src/main/java/com/javaquery/util/json/JSONObject.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.javaquery.util.time.DateTimeFormat;
66
import com.javaquery.util.time.Dates;
77
import org.json.JSONArray;
8+
import org.json.JSONException;
89

910
import java.math.BigDecimal;
1011
import java.math.BigInteger;
@@ -27,12 +28,37 @@ public JSONObject(String json) {
2728
this(new org.json.JSONObject(json));
2829
}
2930

31+
public JSONObject(){
32+
this(new org.json.JSONObject());
33+
}
34+
3035
/** @param jsonObject {@link org.json.JSONObject} to prepare {@link JSONObject} */
3136
public JSONObject(org.json.JSONObject jsonObject) {
3237
ROOT = jsonObject;
3338
CACHED_OBJECT = new HashMap<>();
3439
}
3540

41+
/**
42+
* Put a key/value pair in the JSONObject. If the value is <code>null</code>, then the
43+
* key will be removed from the JSONObject if it is present.
44+
*
45+
* @param key
46+
* A key string.
47+
* @param value
48+
* An object which is the value. It should be of one of these
49+
* types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
50+
* String, or the JSONObject.NULL object.
51+
* @return this.
52+
* @throws JSONException
53+
* If the value is non-finite number.
54+
* @throws NullPointerException
55+
* If the key is <code>null</code>.
56+
*/
57+
public JSONObject put(String key, Object value){
58+
ROOT.put(key, value);
59+
return this;
60+
}
61+
3662
/**
3763
* Get an optional boolean associated with a key. It returns false if there is no such key, or if
3864
* the value is not Boolean.TRUE or the String "true".

src/test/java/com/javaquery/util/json/TestJSONObject.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public class TestJSONObject {
2121
"{\"author\":\"vicky\",\"created\":\"2021-01-20 10:00:10\",\"items\":{\"item\":[{\"ppu\":0.55,\"batters\":{\"batter\":[{\"available\":true,\"id\":\"1001\",\"type\":\"Regular\"},{\"available\":false,\"id\":\"1002\",\"type\":\"Chocolate\"},{\"id\":\"1003\",\"type\":\"Blueberry\"},{\"id\":\"1004\",\"type\":\"Devil's Food\"}]},\"name\":\"Cake\",\"id\":\"0001\",\"type\":\"donut\",\"topping\":[{\"id\":\"5001\",\"type\":\"None\"},{\"id\":\"5002\",\"type\":\"Glazed\"},{\"id\":\"5005\",\"type\":\"Sugar\",\"kg\":652398},{\"id\":\"5007\",\"type\":\"Powdered Sugar\",\"kg\":875},{\"id\":\"5006\",\"type\":\"Chocolate with Sprinkles\"},{\"id\":\"5003\",\"type\":\"Chocolate\"},{\"id\":\"5004\",\"type\":\"Maple\"}]}]}}";
2222
private static final JSONObject JSONOBJECT = new JSONObject(STRING_JSON_OBJECT);
2323

24+
@Test
25+
public void test_put(){
26+
JSONObject jsonObject = new JSONObject();
27+
jsonObject.put("a", 10);
28+
Assertions.assertEquals(10, jsonObject.optInt("a"));
29+
}
30+
2431
@Test
2532
public void test_optBoolean() {
2633
Assertions.assertTrue(JSONOBJECT.optBoolean("items.item[0].batters.batter[0].available"));

0 commit comments

Comments
 (0)