Skip to content

The JSON property name for 'ServerlessWorkflow.Sdk.Models.SwitchStateDefinition.name' collides with another property. #48

Closed
@ElanHasson

Description

@ElanHasson

What happened:
Unable to parse a workflow with a dataCondition property as it's serialized as the property name name which is also used by stateDefinition.Name.

What you expected to happen:
Should have the json property dataContion and not name.
How to reproduce it:
Parse this workflow:

{
  "id": "helloworld",
  "version": "1.0.0",
  "specVersion": "0.8",
  "name": "Hello World Workflow",
  "description": "Inject Hello World",
  "start": "hello-state",
  "states": [
    {
      "name": "hello-state",
      "type": "inject",
      "data": {
        "result": "Hello World!",
        "age": 10,
        "date": "2019-10-10T10:10:10.000Z",
        "cool": true,
        "lame": false
      },
      "transition": {
        "nextState": "check-if-cool"
      }
    },
    {
      "name": "check-if-cool",
      "type": "switch",
      "dataConditions": [
        {
          "condition": "$.cool == true",
          "transition": "kid-is-cool"
        }
      ],
      "defaultCondition": {
        "transition": "kid-is-not-cool"
      }
    },
    {
      "name": "kid-is-not-cool",
      "type": "inject",
      "data": {
        "result": "Kid is NOT cool! 🥹"
      },
      "end": true
    },
    {
      "name": "kid-is-cool",
      "type": "inject",
      "data": {
        "result": "Kid is cool! 😎"
      },
      "end": true
    }
  ]
}

Anything else we need to know?:
Stack trace:

Unhandled exception. System.InvalidOperationException: The JSON property name for 'ServerlessWorkflow.Sdk.Models.SwitchStateDefinition.name' collides with another property.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, String propertyName)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.JsonPropertyInfoList.AddPropertyWithConflictResolution(JsonPropertyInfo jsonPropertyInfo, PropertyHierarchyResolutionState& state)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean constructorHasSetsRequiredMembersAttribute, PropertyHierarchyResolutionState& state)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)
   at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
--- End of stack trace from previous location ---
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.AbstractClassConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
   at ServerlessWorkflow.Sdk.Serialization.Serializer.Json.Deserialize[T](String json)
   at ServerlessWorkflow.Sdk.Services.IO.WorkflowReader.ReadAsync(Stream stream, WorkflowReaderOptions options, CancellationToken cancellationToken)
   at ServerlessWorkflow.Sdk.IWorkflowReaderExtensions.ReadAsync(IWorkflowReader reader, Stream stream, CancellationToken cancellationToken)

Environment:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions