Search Results for

    Show / Hide Table of Contents
    View Source

    Class JsonValueConverter

    The default converter for all property editors that expose a JSON value type

    Inheritance
    object
    PropertyValueConverterBase
    Namespace: Umbraco.Cms.Core.PropertyEditors.ValueConverters
    Assembly: Umbraco.Infrastructure.dll
    Syntax
    [DefaultPropertyValueConverter]
    public class JsonValueConverter : PropertyValueConverterBase, IDeliveryApiPropertyValueConverter, IPropertyValueConverter, IDiscoverable
    Remarks

    Since this is a default (umbraco) converter it will be ignored if another converter found conflicts with this one.

    Constructors

    View Source

    JsonValueConverter(PropertyEditorCollection, ILogger<JsonValueConverter>)

    Initializes a new instance of the JsonValueConverter class.

    Declaration
    public JsonValueConverter(PropertyEditorCollection propertyEditors, ILogger<JsonValueConverter> logger)
    Parameters
    Type Name Description
    PropertyEditorCollection propertyEditors
    ILogger<JsonValueConverter> logger

    Methods

    View Source

    ConvertIntermediateToDeliveryApiObject(IPublishedElement, IPublishedPropertyType, PropertyCacheLevel, object?, bool, bool)

    Converts an intermediate JSON value, represented as a System.Text.Json.JsonDocument, to a System.Text.Json.Nodes.JsonNode object suitable for use by the Delivery API.

    Declaration
    public object? ConvertIntermediateToDeliveryApiObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding)
    Parameters
    Type Name Description
    IPublishedElement owner

    The published element that owns the property.

    IPublishedPropertyType propertyType

    Metadata describing the property type.

    PropertyCacheLevel referenceCacheLevel

    The cache level for property references.

    object inter

    The intermediate value to convert; expected to be a System.Text.Json.JsonDocument.

    bool preview

    True if the conversion is for preview mode; otherwise, false.

    bool expanding

    True if nested properties are being expanded during conversion; otherwise, false.

    Returns
    Type Description
    object

    A System.Text.Json.Nodes.JsonNode representing the converted value for the Delivery API, or null if inter is not a System.Text.Json.JsonDocument.

    View Source

    ConvertSourceToIntermediate(IPublishedElement, IPublishedPropertyType, object?, bool)

    Converts the source value to an intermediate representation suitable for further processing.

    Declaration
    public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview)
    Parameters
    Type Name Description
    IPublishedElement owner

    The published element that owns the property.

    IPublishedPropertyType propertyType

    The type of the published property.

    object source

    The source value to convert.

    bool preview

    Indicates whether the conversion is for preview mode.

    Returns
    Type Description
    object

    If source is a JSON string, returns a System.Text.Json.JsonDocument; if not, returns the original string; returns null if source is null.

    View Source

    GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType)

    Determines the appropriate cache level for a property when accessed via the delivery API.

    Declaration
    public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType)
    Parameters
    Type Name Description
    IPublishedPropertyType propertyType

    The published property type for which to retrieve the cache level.

    Returns
    Type Description
    PropertyCacheLevel

    The PropertyCacheLevel to be used for the specified property type.

    View Source

    GetDeliveryApiPropertyValueType(IPublishedPropertyType)

    Returns the .NET type used to represent the property value for the Delivery API, based on the specified published property type.

    Declaration
    public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType)
    Parameters
    Type Name Description
    IPublishedPropertyType propertyType

    The published property type for which to determine the Delivery API value type.

    Returns
    Type Description
    Type

    The System.Type representing the Delivery API property value, typically System.Text.Json.Nodes.JsonNode.

    View Source

    GetPropertyCacheLevel(IPublishedPropertyType)

    Gets the property cache level for the specified property type.

    Declaration
    public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
    Parameters
    Type Name Description
    IPublishedPropertyType propertyType

    The property type for which to determine the cache level.

    Returns
    Type Description
    PropertyCacheLevel

    Always returns Element.

    Remarks

    This method overrides the base implementation and always returns Element regardless of the property type.

    View Source

    GetPropertyValueType(IPublishedPropertyType)

    Gets the type of the property value for the given published property type. This implementation always returns System.Text.Json.JsonDocument as the property value type.

    Declaration
    public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
    Parameters
    Type Name Description
    IPublishedPropertyType propertyType

    The published property type.

    Returns
    Type Description
    Type

    The System.Type representing System.Text.Json.JsonDocument.

    Remarks

    We return a JsonDocument here because it's readonly and faster than JsonNode.

    View Source

    IsConverter(IPublishedPropertyType)

    It is a converter for any value type that is "JSON" Unless it's in the Excluded Property Editors list The new MediaPicker 3 stores JSON but we want to use its own ValueConvertor

    Declaration
    public override bool IsConverter(IPublishedPropertyType propertyType)
    Parameters
    Type Name Description
    IPublishedPropertyType propertyType

    The published property type to check.

    Returns
    Type Description
    bool

    True if this converter can convert the property type.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX