Skip to content

Commit 3a48bdc

Browse files
committed
@GenIgnore non-canonical getters/setters of Redis[Connect]Options.endpoints
The `RedisOptions` class has a field `endpoints` of type `List<String>` for which multiple accessors and mutators exist: - `getEndpoints()`: the canonical getter - `setEndpoints()`: the canonical setter - `getEndpoint()`: returns the first element of the list - `setEndpoint()`: turns the list into a single-element list - `addEndpoint()`: adds one element to the list - `setConnectionString()`: same as `setEndpoint()` - `addConnectionString()`: same as `addEndpoint()` The `RedisConnectOptions` class, which is `public` but is only used internally, has the same problem. All these methods are treated as individual properties by the code generator that produces the JSON serialization/deserialization classes, even though they are all backed by a single field. Since the code generator considers properties in declaration order (in upcoming Vert.x 5; it is lexicographic order in Vert.x 4), we had to reorder the methods so that serialization and deserialization does not lose information. That is arguably a provisional solution, as it is very much not obvious that declaration order matters. This commit provides a permanent solution: all the non-canonical methods are marked as `@GenIgnore`. Only the `getEndpoints()` and `setEndpoints()` methods are used for serialization/deserialization. This is a breaking change, so it shall not be backported to Vert.x 4 and shall be documented as such.
1 parent 6730109 commit 3a48bdc

File tree

4 files changed

+9
-39
lines changed

4 files changed

+9
-39
lines changed

src/main/generated/io/vertx/redis/client/RedisConnectOptionsConverter.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,6 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, RedisCo
4040
obj.setPassword((String)member.getValue());
4141
}
4242
break;
43-
case "endpoint":
44-
break;
45-
case "connectionStrings":
46-
if (member.getValue() instanceof JsonArray) {
47-
((Iterable<Object>)member.getValue()).forEach( item -> {
48-
if (item instanceof String)
49-
obj.addConnectionString((String)item);
50-
});
51-
}
52-
break;
53-
case "connectionString":
54-
if (member.getValue() instanceof String) {
55-
obj.setConnectionString((String)member.getValue());
56-
}
57-
break;
5843
case "endpoints":
5944
if (member.getValue() instanceof JsonArray) {
6045
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
@@ -87,9 +72,6 @@ static void toJson(RedisConnectOptions obj, java.util.Map<String, Object> json)
8772
if (obj.getPassword() != null) {
8873
json.put("password", obj.getPassword());
8974
}
90-
if (obj.getEndpoint() != null) {
91-
json.put("endpoint", obj.getEndpoint());
92-
}
9375
if (obj.getEndpoints() != null) {
9476
JsonArray array = new JsonArray();
9577
obj.getEndpoints().forEach(item -> array.add(item));

src/main/generated/io/vertx/redis/client/RedisOptionsConverter.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, RedisOp
3030
obj.setNetClientOptions(new io.vertx.core.net.NetClientOptions((io.vertx.core.json.JsonObject)member.getValue()));
3131
}
3232
break;
33-
case "endpoint":
34-
if (member.getValue() instanceof String) {
35-
obj.setEndpoint((String)member.getValue());
36-
}
37-
break;
3833
case "endpoints":
3934
if (member.getValue() instanceof JsonArray) {
4035
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
@@ -45,19 +40,6 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, RedisOp
4540
obj.setEndpoints(list);
4641
}
4742
break;
48-
case "connectionStrings":
49-
if (member.getValue() instanceof JsonArray) {
50-
((Iterable<Object>)member.getValue()).forEach( item -> {
51-
if (item instanceof String)
52-
obj.addConnectionString((String)item);
53-
});
54-
}
55-
break;
56-
case "connectionString":
57-
if (member.getValue() instanceof String) {
58-
obj.setConnectionString((String)member.getValue());
59-
}
60-
break;
6143
case "maxWaitingHandlers":
6244
if (member.getValue() instanceof Number) {
6345
obj.setMaxWaitingHandlers(((Number)member.getValue()).intValue());
@@ -148,9 +130,6 @@ static void toJson(RedisOptions obj, java.util.Map<String, Object> json) {
148130
if (obj.getNetClientOptions() != null) {
149131
json.put("netClientOptions", obj.getNetClientOptions().toJson());
150132
}
151-
if (obj.getEndpoint() != null) {
152-
json.put("endpoint", obj.getEndpoint());
153-
}
154133
if (obj.getEndpoints() != null) {
155134
JsonArray array = new JsonArray();
156135
obj.getEndpoints().forEach(item -> array.add(item));

src/main/java/io/vertx/redis/client/RedisConnectOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.vertx.redis.client;
1717

1818
import io.vertx.codegen.annotations.DataObject;
19+
import io.vertx.codegen.annotations.GenIgnore;
1920
import io.vertx.codegen.json.annotations.JsonGen;
2021
import io.vertx.core.json.JsonObject;
2122

@@ -158,6 +159,7 @@ public RedisConnectOptions setPassword(String password) {
158159
*
159160
* @return the Redis connection string URI
160161
*/
162+
@GenIgnore
161163
public String getEndpoint() {
162164
if (endpoints == null || endpoints.isEmpty()) {
163165
return RedisOptions.DEFAULT_ENDPOINT;
@@ -175,6 +177,7 @@ public String getEndpoint() {
175177
*
176178
* @see <a href="https://www.iana.org/assignments/uri-schemes/prov/redis">Redis scheme on iana.org</a>
177179
*/
180+
@GenIgnore
178181
public RedisConnectOptions addConnectionString(String connectionString) {
179182
if (endpoints == null) {
180183
endpoints = new ArrayList<>();
@@ -191,6 +194,7 @@ public RedisConnectOptions addConnectionString(String connectionString) {
191194
* @return fluent self.
192195
* @see <a href="https://www.iana.org/assignments/uri-schemes/prov/redis">Redis scheme on iana.org</a>
193196
*/
197+
@GenIgnore
194198
public RedisConnectOptions setConnectionString(String connectionString) {
195199
if (endpoints == null) {
196200
endpoints = new ArrayList<>();

src/main/java/io/vertx/redis/client/RedisOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public RedisOptions setNetClientOptions(NetClientOptions netClientOptions) {
153153
*
154154
* @return the Redis connection string URI
155155
*/
156+
@GenIgnore
156157
public String getEndpoint() {
157158
if (endpoints == null || endpoints.isEmpty()) {
158159
return DEFAULT_ENDPOINT;
@@ -170,6 +171,7 @@ public String getEndpoint() {
170171
* @deprecated see {@link #setConnectionString(String connectionString)} for a better naming
171172
*/
172173
@Deprecated
174+
@GenIgnore
173175
public RedisOptions addEndpoint(String connectionString) {
174176
if (endpoints == null) {
175177
endpoints = new ArrayList<>();
@@ -187,6 +189,7 @@ public RedisOptions addEndpoint(String connectionString) {
187189
* @deprecated see {@link #setConnectionString(String connectionString)} for a better naming
188190
*/
189191
@Deprecated
192+
@GenIgnore
190193
public RedisOptions setEndpoint(String connectionString) {
191194
if (endpoints == null) {
192195
endpoints = new ArrayList<>();
@@ -206,6 +209,7 @@ public RedisOptions setEndpoint(String connectionString) {
206209
* @return fluent self.
207210
* @see <a href="https://www.iana.org/assignments/uri-schemes/prov/redis">Redis scheme on iana.org</a>
208211
*/
212+
@GenIgnore
209213
public RedisOptions addConnectionString(String connectionString) {
210214
if (endpoints == null) {
211215
endpoints = new ArrayList<>();
@@ -222,6 +226,7 @@ public RedisOptions addConnectionString(String connectionString) {
222226
* @return fluent self.
223227
* @see <a href="https://www.iana.org/assignments/uri-schemes/prov/redis">Redis scheme on iana.org</a>
224228
*/
229+
@GenIgnore
225230
public RedisOptions setConnectionString(String connectionString) {
226231
if (endpoints == null) {
227232
endpoints = new ArrayList<>();

0 commit comments

Comments
 (0)