Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeException: Unsupported record value type: class java.util.LinkedHashMap #1001

Closed
tuncaulubilge opened this issue Jul 20, 2018 · 3 comments

Comments

@tuncaulubilge
Copy link
Contributor

tuncaulubilge commented Jul 20, 2018

Using apollo-android 0.5.0

Trying to use a custom scalar type but normalisation inside SqlNormalizedCache fails with the following error inside RecordFieldJsonAdapter

RuntimeException: Unsupported record value type: class java.util.LinkedHashMap

The data it's trying to parse is a mixed json array, and we are serialising it as a string using CustomTypeAdapters. However, RecordFieldJsonAdapter used by SqlNormalizedCache does not use custom type adapters and tries to serialise it as a LinkedHashMap.

Here is a sample from our json:

      "byline": [
        {
          "name": "author",
          "attributes": {
            "slug": "sample-author"
          },
          "children": [
            {
              "name": "text",
              "attributes": {
                "value": "Sample Author"
              },
              "children": []
            }
          ]
        },
        {
          "name": "inline",
          "children": [
            {
              "name": "text",
              "attributes": {
                "value": ", Sample title"
              },
              "children": []
            }
          ]
        }
      ],

This byline has a custom scalar type defined in the schema and being parsed as a string. We don't want to use strict types on this object as it's highly volatile. Is there a way to customize json serialisation? Am I missing something in the schema?

@sav007
Copy link
Contributor

sav007 commented Jul 23, 2018

If you register custom type adapter com.apollographql.apollo.response.CustomTypeAdapter in T decode(@NotNull CustomTypeValue value) you will get com.apollographql.apollo.response.CustomTypeValue.GraphQLJsonString that is JSON string.
Then it's up to you to define how to parse it and convert to custom type you want.

@tuncaulubilge
Copy link
Contributor Author

That's exactly what I'm doing, and apollo is able to parse it as a string.

The problem occurs when apollo tries to persist this data using the SqlNormalizedCache. So, my guess is apollo is not using the custom type adapters while trying to serialise data for persistence.

@sav007
Copy link
Contributor

sav007 commented Oct 23, 2018

I think we can close this issue.

@sav007 sav007 closed this as completed Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants