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

SynchronizationManager.sync() throws JSON Decoding exception #145

Open
oliveira-marcio opened this issue Dec 13, 2023 · 0 comments
Open

Comments

@oliveira-marcio
Copy link

oliveira-marcio commented Dec 13, 2023

Hi guys, I've noticed that when we try to use the Sync API with the SyncronizationManager in the ContentfulPersistence library, the sync() method throws a JSON Decoding Error when we have a content type in the space with a Reference field that references content from another space.

The ContentfulPersistence version I'm using is 0.17.7

The exception message I'm having is

"Cannot initialize FieldType from invalid String value ResourceLink"

I did some investigation inside the library and found that this ResourceLink type is not supported by the decodable models:

public enum FieldType: String, Decodable {
    /// An array of links or symbols
    case array = "Array"

    /// A link to an Asset
    case asset = "Asset"

    /// A boolean value, true or false
    case boolean = "Boolean"

    /// A date value with optional time component
    case date = "Date"

    /// A link to an Entry
    case entry = "Entry"

    /// A numeric integer value
    case integer = "Integer"

    /// A link to an Asset or Entry
    case link = "Link"

    /// A location value, consists of latitude and longitude
    case location = "Location"

    /// A floating point number value
    case number = "Number"

    /// A JSON object value
    case object = "Object"

    /// A short text string, can be part of an array
    case symbol = "Symbol"

    /// A longer text string
    case text = "Text"

    /// An unknown kind of value
    case none = "None"

    /// The rich text field type.
    case richText = "RichText"
}

Is that the supposed behavior? I believe this kind of content could be just ignored instead of throwing exceptions and aborting the whole synchronization to persistence.

This is a sample of the response that the Sync API returns when called by the SyncronizationManager in the app with the 2 entries we have in the space where one of them contains the ResourceLink type:

{
  "sys": {
    "type": "Array"
  },
  "total": 2,
  "skip": 0,
  "limit": 100,
  "items": [
    {
      "sys": {
        "space": {
          "sys": {
            "type": "Link",
            "linkType": "Space",
            "id": "sguoqsshwt8t"
          }
        },
        "id": "resultNarrative",
        "type": "ContentType",
        "createdAt": "2023-06-30T12:16:02.678Z",
        "updatedAt": "2023-06-30T12:16:02.678Z",
        "environment": {
          "sys": {
            "id": "develop",
            "type": "Link",
            "linkType": "Environment"
          }
        },
        "revision": 1
      },
      "displayField": "key",
      "name": "ResultNarrative",
      "description": "This model acts as an access point to the result narrative content models & content found on the performance space",
      "fields": [
        {
          "id": "key",
          "name": "key",
          "type": "Symbol",
          "localized": false,
          "required": false,
          "disabled": false,
          "omitted": false
        },
        {
          "id": "resultNarrativeKit",
          "name": "Results Narrative Kit",
          "type": "ResourceLink",
          "localized": false,
          "required": true,
          "disabled": false,
          "omitted": false,
          "allowedResources": [
            {
              "type": "Contentful:Entry",
              "source": "crn:contentful:::content:spaces/lnbo4srla2av",
              "contentTypes": [
                "resultNarrativeKit"
              ]
            }
          ]
        }
      ]
    },
    {
      "sys": {
        "space": {
          "sys": {
            "type": "Link",
            "linkType": "Space",
            "id": "sguoqsshwt8t"
          }
        },
        "id": "consultationLandingScreen",
        "type": "ContentType",
        "createdAt": "2023-05-11T13:45:45.732Z",
        "updatedAt": "2023-05-11T13:45:45.732Z",
        "environment": {
          "sys": {
            "id": "develop",
            "type": "Link",
            "linkType": "Environment"
          }
        },
        "revision": 1
      },
      "displayField": "key",
      "name": "Consultation Landing Screen",
      "description": "Content model that is used for populating views on the consultation landing screen.",
      "fields": [
        {
          "id": "key",
          "name": "key",
          "type": "Symbol",
          "localized": false,
          "required": true,
          "disabled": false,
          "omitted": false
        },
        {
          "id": "description",
          "name": "description",
          "type": "Symbol",
          "localized": false,
          "required": false,
          "disabled": false,
          "omitted": false
        }
      ]
    }
  ]
}

When I remove this entry from the space, the synchronization works normally.

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

1 participant