awslabs / aws-mobile-appsync-sdk-android

Android SDK for AWS AppSync.
https://docs.amplify.aws/sdk/api/graphql/q/platform/android/
Apache License 2.0
105 stars 58 forks source link

Wrong serialisation for Enum type in WebSocketConnectionManager #407

Open ukevgen opened 1 year ago

ukevgen commented 1 year ago

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):