Skip to content

Commit

Permalink
Address change in JSON.GET command without path (#3858)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 7, 2024
1 parent 36668bc commit 4ca869e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
3 changes: 1 addition & 2 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3621,8 +3621,7 @@ public final CommandObject<String> jsonMerge(String key, Path path, Object pojo)
}

public final CommandObject<Object> jsonGet(String key) {
return new CommandObject<>(commandArguments(JsonCommand.GET).key(key),
protocol != RedisProtocol.RESP3 ? JSON_GENERIC_OBJECT : JsonBuilderFactory.JSON_OBJECT);
return new CommandObject<>(commandArguments(JsonCommand.GET).key(key), JSON_GENERIC_OBJECT);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ public void testJsonMergeOldPath() {

@Test
@Deprecated
public void testJsonGenericObjectResp2() {
assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));

public void testJsonGenericObject() {
String key = "user:1000";

Person person = new Person();
Expand All @@ -256,29 +254,6 @@ public void testJsonGenericObjectResp2() {
assertThat(resultMap, hasEntry("age", 30.0));
}

@Test
@Deprecated
public void testJsonGenericObjectResp3() {
assumeThat(protocol, equalTo(RedisProtocol.RESP3));

String key = "user:1000";

Person person = new Person("John Doe", 30);

String setResult = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person));
assertThat(setResult, equalTo("OK"));

Object getRoot = exec(commandObjects.jsonGet(key));
assertThat(getRoot, instanceOf(JSONArray.class));

JSONObject expectedPerson = new JSONObject();
expectedPerson.put("name", "John Doe");
expectedPerson.put("age", 30);

JSONArray expected = new JSONArray().put(expectedPerson);
assertThat(getRoot, jsonEquals(expected));
}

@Test
@Deprecated
public void testJsonGetWithClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public void setUp() {

@Test
public void basicSetGetShouldSucceed() {
Assume.assumeFalse(protocol == RedisProtocol.RESP3);

// naive set with a path
jsonV2.jsonSetWithEscape("null", ROOT_PATH, (Object) null);
assertJsonArrayEquals(jsonArray((Object) null), jsonV2.jsonGet("null", ROOT_PATH));
Expand All @@ -72,29 +70,6 @@ public void basicSetGetShouldSucceed() {
assertJsonArrayEquals(jsonArray("strung"), jsonV2.jsonGet("obj", p));
}

@Test
public void basicSetGetShouldSucceedResp3() {
Assume.assumeTrue(protocol == RedisProtocol.RESP3);

// naive set with a path
jsonV2.jsonSetWithEscape("null", ROOT_PATH, (Object) null);
assertJsonArrayEquals(jsonArray((Object) null), jsonV2.jsonGet("null", ROOT_PATH));

// real scalar value and no path
jsonV2.jsonSetWithEscape("str", "strong");
assertJsonArrayEquals(jsonArray("strong"), jsonV2.jsonGet("str"));

// a slightly more complex object
IRLObject obj = new IRLObject();
jsonV2.jsonSetWithEscape("obj", obj);
assertJsonArrayEquals(jsonArray(new JSONObject(gson.toJson(obj))), jsonV2.jsonGet("obj"));

// check an update
Path2 p = Path2.of(".str");
jsonV2.jsonSet("obj", p, gson.toJson("strung"));
assertJsonArrayEquals(jsonArray("strung"), jsonV2.jsonGet("obj", p));
}

@Test
public void setExistingPathOnlyIfExistsShouldSucceed() {
jsonV2.jsonSetWithEscape("obj", new IRLObject());
Expand Down

0 comments on commit 4ca869e

Please sign in to comment.