awslabs / awslabs/aws-mobile-appsync-sdk-android
Wrong serialisation for Enum type in WebSocketConnectionManager
- Dominant language
- Java
- Stars
- 106
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The JSONObject cant serialise subscription with Enum type JSONObject(subscription.variables().valueMap()). As a result will be smth like this **{“personId”:“2",“personType”:null}}**.
**To Reproduce**
Create any subscription with Enum type as argument and look into this void
```
private synchronized void startSubscription(
@NonNull Subscription subscription,
@NonNull AppSyncSubscriptionCall.Callback callback,
String subscriptionId) {
try {
// Check result to avoid silent failure
boolean enqueued = websocket.send(new JSONObject()
.put("id", subscriptionId)
.put("type", "start")
.put("payload", new JSONObject()
.put("data", (new JSONObject()
.put("query", subscription.queryDocument())
.put("variables", new JSONObject(subscription.variables().valueMap()))).toString())
.put("extensions", new JSONObject()
.put("authorization", subscriptionAuthorizer.getAuthorizationDetails(false, subscription))))
.toString()
);
if (!enqueued) {
callback.onFailure(new ApolloException("WebSocket communication failed."));
}
} catch (JSONException jsonException) {
throw new RuntimeException("Failed to construct subscription registration message.", jsonException);
}
}
```
The lini with
`put("variables", new JSONObject(subscription.variables().valueMap()))).toString())` isn’t working in a correct way with Enum type.
**Expected behavior**
Serialisation for Enum type is correct.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Environment(please complete the following information):**
- AppSync SDK Version: com.amazonaws:aws-android-sdk-appsync:3.3.2
Contributor guide
Research direction
Start at the shown startSubscription method, especially the JSONObject construction around subscription.variables().valueMap(), and reproduce a subscription whose argument uses an Enum. Verify the serialized variables payload and confirm that the enum value is preserved instead of becoming null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, graphql, java
- Domain
- api, mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100