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

Enable the Unsupported Object #419

Open
kosaku-hayashi opened this issue Jul 15, 2024 · 0 comments
Open

Enable the Unsupported Object #419

kosaku-hayashi opened this issue Jul 15, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@kosaku-hayashi
Copy link
Contributor

Description

Currently, if a property or block newly added to Notion is included in the response, a serializer exception is raised and the
The client will stop working.

Example:
Newtonsoft.Json.JsonSerializationException: 'Error converting value "{New property or block}" to type 'Notion.Client.PropertyValueType'

This is because there is no matching enum value for the type string, and the existing StringEnumConverter does not support returning a default value in such cases.
The existing code provides a class that accepts unsupported blocks called UnsupportedBlock, but this is effectively a non-functional state.

// Some other attributes
[JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] <-- It will never be deserialized.
public interface IBlock : IObject, IObjectModificationData
{
    [JsonProperty("type")]
    [JsonConverter(typeof(StringEnumConverter))] <-- Cannot return default value if enum value does not exist
    BlockType Type { get; set; }

    [JsonProperty("has_children")]
    bool HasChildren { get; set; }

    [JsonProperty("in_trash")]
    bool InTrash { get; set; }

    [JsonProperty("parent")]
    IBlockParent Parent { get; set; }
}
public enum BlockType
{
    // Some other Type values

    [EnumMember(Value = "unsupported")] <-- Newly added block type values are never "unsupported".
    Unsupported
}

This problem could be remedied by creating a custom converter that returns a default value (i.e., "UnSupported") if the type string does not match and defining it on the enum side.
Property and PropertyValue also raise the same exception, so it may be necessary to create UnSupportedProperty and UnSupportedPropertyValue in a similar manner.

@KoditkarVedant KoditkarVedant added this to the 4.3.0 milestone Oct 29, 2024
@KoditkarVedant KoditkarVedant added the enhancement New feature or request label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants