Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address change in JSON.GET command without path #3858

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3625,8 +3625,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
Loading