Skip to content

Commit 8e804f3

Browse files
committed
Work around a JsonValue bug (FasterXML/jackson-databind#3063)
1 parent 527ac06 commit 8e804f3

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

allezgo-service/src/main/java/io/allezgo/endpoints/SyncPelotonToGarmin.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import barista.Endpoints;
44
import barista.HttpMethod;
5-
import com.fasterxml.jackson.annotation.JsonValue;
65
import com.google.common.base.Strings;
76
import io.allezgo.client.HttpError;
8-
import io.allezgo.client.Result;
97
import io.allezgo.config.Configuration;
108
import io.allezgo.pipes.PelotonToTcx;
119
import io.allezgo.sink.garmin.GarminActivity;
@@ -51,17 +49,15 @@ public HttpMethod method() {
5149
public Response call(Request request) {
5250
List<String> failingArgs = checkArgs(request);
5351
if (!failingArgs.isEmpty()) {
54-
return new Response(
55-
Result.error("Some required fields were missing or empty: " + failingArgs));
52+
return new Response(null, "Some required fields were missing or empty: " + failingArgs);
5653
}
5754

5855
PelotonClient peloton =
5956
new PelotonClient(
6057
new Configuration.Peloton(request.pelotonEmail, request.pelotonPassword));
6158

6259
if (!peloton.validateLogin()) {
63-
return new Response(
64-
Result.error("Unable to login to Peloton with the provided credentials"));
60+
return new Response(null, "Unable to login to Peloton with the provided credentials");
6561
}
6662

6763
GarminClient garmin =
@@ -72,11 +68,10 @@ public Response call(Request request) {
7268
request.garminPelotonGearName));
7369

7470
if (!garmin.validateLogin()) {
75-
return new Response(
76-
Result.error("Unable to login to Garmin with the provided credentials"));
71+
return new Response(null, "Unable to login to Garmin with the provided credentials");
7772
}
7873

79-
return new Response(Result.ok(syncLast30Days(peloton, garmin)));
74+
return new Response(syncLast30Days(peloton, garmin), null);
8075
}
8176

8277
private static List<String> checkArgs(Request request) {
@@ -114,7 +109,7 @@ public record SyncRecord(
114109
String garminLink,
115110
boolean wasCreated) {}
116111

117-
public record Response(@JsonValue Result<List<SyncRecord>, String> response) {}
112+
public record Response(List<SyncRecord> result, String error) {}
118113

119114
private static List<SyncRecord> syncLast30Days(PelotonClient peloton, GarminClient garmin) {
120115
Instant thirtyDaysAgo = Instant.now().minus(Period.ofDays(30));

barista/src/main/java/barista/Handlers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package barista;
22

3+
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS;
4+
35
import com.google.common.base.Joiner;
46
import io.undertow.server.HttpHandler;
57
import io.undertow.server.HttpServerExchange;
68
import io.undertow.util.HeaderValues;
79
import io.undertow.util.Headers;
810
import io.undertow.util.HttpString;
911
import io.undertow.util.Methods;
10-
1112
import java.util.Optional;
1213
import java.util.Set;
1314

14-
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS;
15-
1615
public final class Handlers {
1716
private static final HttpString ACCESS_CONTROL_ALLOW_ORIGIN =
1817
new HttpString("Access-Control-Allow-Origin");
@@ -154,6 +153,7 @@ private <Request, Response> void openPost(
154153
} catch (Exception e) {
155154
exchange.setStatusCode(500);
156155
exchange.getResponseSender().send("Server Error");
156+
e.printStackTrace();
157157
}
158158
}
159159

0 commit comments

Comments
 (0)