Skip to content

Commit

Permalink
Load the Jackson-based implementation dynamically to avoid ClassNotFound
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Sep 30, 2024
1 parent 547271c commit cba470c
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 48 deletions.
6 changes: 2 additions & 4 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Lettuce 6.4.0 RELEASE NOTES
==============================

The Redis team is delighted to announce general availability of Lettuce 6.4.
The Redis team is delighted to announce the general availability of Lettuce 6.5.

This Lettuce driver is now going to be shipped under the MIT licensing scheme. The `CLIENT SETINFO`
is now working in a fire-and-forget mode to allow better compatibility with Redis servers that do
not support this command.
Great news everybody! Lettuce 6.5.0 comes with RedisJSON support enabled. For more on that please consult with the [RedisJSON documentation](https://redis.io/docs/latest/develop/data-types/json/) and the .

Lettuce 6 supports Redis 2.6+ up to Redis 7.x. In terms of Java runtime, Lettuce requires
at least Java 8 and works with Java 21.
Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add these lines to file pom.xml:
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>6.4.0.RELEASE</version>
<version>6.5.0.RELEASE</version>
</dependency>
```

Expand All @@ -23,7 +23,7 @@ Add these lines to file ivy.xml:
``` xml
<ivy-module>
<dependencies>
<dependency org="io.lettuce" name="lettuce-core" rev="6.4.0.RELEASE"/>
<dependency org="io.lettuce" name="lettuce-core" rev="6.5.0.RELEASE"/>
</dependencies>
</ivy-module>
```
Expand All @@ -34,7 +34,7 @@ Add these lines to file build.gradle:

``` groovy
dependencies {
implementation 'io.lettuce:lettuce-core:6.4.0.RELEASE'
implementation 'io.lettuce:lettuce-core:6.5.0.RELEASE'
}
```

Expand Down
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>6.4.0.BUILD-SNAPSHOT</version>
<version>6.5.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lettuce</name>
Expand Down Expand Up @@ -546,6 +546,21 @@
<scope>test</scope>
</dependency>

<!-- JMH -->

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/lettuce/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.ServiceLoader;

import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.json.DefaultJsonParser;
import io.lettuce.core.json.JsonParser;
import io.lettuce.core.protocol.DecodeBufferPolicies;
import io.lettuce.core.protocol.DecodeBufferPolicy;
Expand Down Expand Up @@ -71,8 +72,6 @@ public class ClientOptions implements Serializable {

public static final TimeoutOptions DEFAULT_TIMEOUT_OPTIONS = TimeoutOptions.enabled();

public static final JsonParser DEFAULT_JSON_PARSER = DefaultJsonParser.INSTANCE;

private final boolean autoReconnect;

private final boolean cancelCommandsOnReconnectFailure;
Expand Down Expand Up @@ -192,7 +191,7 @@ public static class Builder {

private Charset scriptCharset = DEFAULT_SCRIPT_CHARSET;

private JsonParser jsonParser = DEFAULT_JSON_PARSER;
private JsonParser jsonParser;

private SocketOptions socketOptions = DEFAULT_SOCKET_OPTIONS;

Expand All @@ -203,6 +202,8 @@ public static class Builder {
private TimeoutOptions timeoutOptions = DEFAULT_TIMEOUT_OPTIONS;

protected Builder() {
Iterator<JsonParser> services = ServiceLoader.load(JsonParser.class).iterator();
jsonParser = services.hasNext() ? services.next() : null;
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/io/lettuce/core/json/DefaultJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
*/
public class DefaultJsonParser implements JsonParser {

public static final DefaultJsonParser INSTANCE = new DefaultJsonParser();

private DefaultJsonParser() {
}

@Override
public JsonValue loadJsonValue(ByteBuffer bytes) {
return new UnproccessedJsonValue(bytes, this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.lettuce.core.json.DefaultJsonParser
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RedisJsonCommandBuilderUnitTests {

public static final String ID_BIKE_6 = "{\"id\":\"bike6\"}";

public static final JsonParser PARSER = DefaultJsonParser.INSTANCE;
public static final JsonParser PARSER = new DefaultJsonParser();

public static final JsonValue ELEMENT = PARSER.createJsonValue(ID_BIKE_6);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DefaultJsonParserUnitTests {
void loadJsonValue() {
final String unprocessed = "{\"a\":1,\"b\":2}";

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue jsonValue = parser.loadJsonValue(ByteBuffer.wrap(unprocessed.getBytes()));

assertThat(jsonValue).isNotNull();
Expand All @@ -35,7 +35,7 @@ void loadJsonValue() {
void createJsonValue() {
final String unprocessed = "\"someValue\"";

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue jsonValue = parser.createJsonValue(ByteBuffer.wrap(unprocessed.getBytes()));

assertThat(jsonValue).isNotNull();
Expand All @@ -47,14 +47,14 @@ void createJsonValue() {
void createJsonObject() {
final String unprocessed = "{\"a\":1,\"b\":2}";

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue jsonValue = parser.createJsonObject();

assertThat(jsonValue).isNotNull();
assertThat(jsonValue.isJsonObject()).isTrue();
assertThat(jsonValue.asJsonObject().size()).isZero();

parser = DefaultJsonParser.INSTANCE;
parser = new DefaultJsonParser();
jsonValue = parser.createJsonValue(ByteBuffer.wrap(unprocessed.getBytes()));

assertThat(jsonValue).isNotNull();
Expand All @@ -72,7 +72,7 @@ void createJsonObject() {

@Test
void createJsonArray() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue jsonValue = parser.createJsonArray();

assertThat(jsonValue).isNotNull();
Expand All @@ -93,7 +93,7 @@ void createJsonArray() {
void parsingIssues() {
final String unprocessed = "{a\":1,\"b\":2}";

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();

assertThatThrownBy(() -> parser.createJsonValue(unprocessed)).isInstanceOf(RedisJsonException.class);
assertThatThrownBy(() -> parser.createJsonValue(ByteBuffer.wrap(unprocessed.getBytes())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DelegateJsonArrayUnitTests {

@Test
void add() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("\"test\"")).add(parser.createJsonValue("\"test2\""))
.add(parser.createJsonValue("\"test3\""));
Expand All @@ -37,7 +37,7 @@ void add() {

@Test
void addCornerCases() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(null).add(parser.createJsonValue("null")).add(parser.createJsonValue("\"test3\""));

Expand All @@ -52,7 +52,7 @@ void addCornerCases() {

@Test
void getCornerCases() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("\"test\"")).add(parser.createJsonValue("\"test2\""))
.add(parser.createJsonValue("\"test3\""));
Expand All @@ -63,7 +63,7 @@ void getCornerCases() {

@Test
void addAll() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray array = new DelegateJsonArray();
array.add(parser.createJsonValue("\"test\"")).add(parser.createJsonValue("\"test2\""))
.add(parser.createJsonValue("\"test3\""));
Expand All @@ -83,7 +83,7 @@ void addAll() {

@Test
void asList() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("1")).add(parser.createJsonValue("2")).add(parser.createJsonValue("3"));

Expand All @@ -95,7 +95,7 @@ void asList() {

@Test
void getFirst() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("\"test\"")).add(parser.createJsonValue("\"test2\""))
.add(parser.createJsonValue("\"test3\""));
Expand All @@ -107,7 +107,7 @@ void getFirst() {

@Test
void iterator() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("1")).add(parser.createJsonValue("2")).add(parser.createJsonValue("3"));

Expand All @@ -120,7 +120,7 @@ void iterator() {

@Test
void remove() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("1")).add(parser.createJsonValue("2")).add(parser.createJsonValue("3"));

Expand All @@ -132,7 +132,7 @@ void remove() {

@Test
void replace() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonArray underTest = new DelegateJsonArray();
underTest.add(parser.createJsonValue("1")).add(parser.createJsonValue("2")).add(parser.createJsonValue("3"));
underTest.replace(1, parser.createJsonValue("4"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DelegateJsonObjectUnitTests {

@Test
void put() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonObject underTest = new DelegateJsonObject();

underTest.put("test", parser.createJsonValue("\"test\"")).put("test2", parser.createJsonValue("1")).put("test2",
Expand All @@ -31,7 +31,7 @@ void put() {

@Test
void remove() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
DelegateJsonObject underTest = new DelegateJsonObject();

underTest.put("test", parser.createJsonValue("\"test\"")).put("test2", parser.createJsonValue("1")).remove("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DelegateJsonValueUnitTests {

@Test
void testString() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue underTest = parser.createJsonValue("\"test\"");

assertThat(underTest.toString()).isEqualTo("\"test\"");
Expand All @@ -44,7 +44,7 @@ void testString() {

@Test
void testNumber() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue underTest = parser.createJsonValue("1");

assertThat(underTest.toString()).isEqualTo("1");
Expand All @@ -70,7 +70,7 @@ void testNumber() {

@Test
void testNumberExtended() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue underTest = parser.createJsonValue("1");

assertThat(underTest.isNumber()).isTrue();
Expand All @@ -92,7 +92,7 @@ void testNumberExtended() {

@Test
void testBoolean() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue underTest = parser.createJsonValue("true");

assertThat(underTest.toString()).isEqualTo("true");
Expand All @@ -118,7 +118,7 @@ void testBoolean() {

@Test
void testNull() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
JsonValue underTest = parser.createJsonValue("null");

assertThat(underTest.toString()).isEqualTo("null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void asString() {
final String unprocessed = "{\"a\":1,\"b\":2}";
final String modified = "{\"a\":1}";

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap(unprocessed.getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand All @@ -55,7 +55,7 @@ void asString() {

@Test
void asTextual() {
DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap("\"textual\"".getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand All @@ -72,7 +72,7 @@ void asTextual() {
@Test
void asNull() {

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap("null".getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand All @@ -88,7 +88,7 @@ void asNull() {
@Test
void asNumber() {

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap("1".getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand All @@ -105,7 +105,7 @@ void asNumber() {
@Test
void asBoolean() {

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap("true".getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand All @@ -122,7 +122,7 @@ void asBoolean() {
@Test
void asArray() {

DefaultJsonParser parser = DefaultJsonParser.INSTANCE;
DefaultJsonParser parser = new DefaultJsonParser();
ByteBuffer buffer = ByteBuffer.wrap("[1,2,3,4]".getBytes());
UnproccessedJsonValue underTest = new UnproccessedJsonValue(buffer, parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JsonValueListOutputUnitTests {

@Test
void set() {
JsonValueListOutput<String, String> sut = new JsonValueListOutput<>(StringCodec.UTF8, DefaultJsonParser.INSTANCE);
JsonValueListOutput<String, String> sut = new JsonValueListOutput<>(StringCodec.UTF8, new DefaultJsonParser());
sut.multi(2);
sut.set(ByteBuffer.wrap("[1,2,3]".getBytes()));
sut.set(ByteBuffer.wrap("world".getBytes()));
Expand Down
Loading

0 comments on commit cba470c

Please sign in to comment.