RicoSuter / VisualJsonEditor

A JSON schema based file editor for Windows.
http://visualjsoneditor.org
MIT License
349 stars 87 forks source link

Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JValue'. #15

Closed deaquino closed 7 years ago

deaquino commented 7 years ago

I have an object with multiple properties (all of them the same type)

at VisualJsonEditor.Models.JsonObjectModel.FromJson(JObject obj, JsonSchema4 schema) in \src\VisualJsonEditor\Models\JsonObjectModel.cs:line 98 at VisualJsonEditor.Models.JsonObjectModel.FromJson(String jsonData, JsonSchema4 schema) in \src\VisualJsonEditor\Models\JsonObjectModel.cs:line 62 at VisualJsonEditor.Models.JsonDocumentModel.<>c__DisplayClass28_0.b__0() in \src\VisualJsonEditor\Models\JsonDocumentModel.cs:line 120 at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()

RicoSuter commented 7 years ago

Can you provide a sample schema?

deaquino commented 7 years ago

These are the files that are causing the exception.

Thank you!

{
  "Activities": {
    "Enabled": true,
    "InvokeMode": "Watcher",
    "Area": "Activities",
    "CsvSettings": {
      "Delimiter": ";",
      "DateFormat": "yyyy-MM-dd'T'HH:mm:ss'Z'",
      "Headers": {
        "HasHeaders": true,
        "CustomHeaders": [
          "ActivityId",
          "StartDate",
          "EndDate"
        ]
      },
      "Trim": true,
      "BatchSleep": "00:00:00",
      "BatchSize": null,
      "MaxFileErrors": null
    },
    "ExcelSettings": null,
    "ExecutionSettings": {
      "Attempts": 3,
      "SleepInterval": "00:00:05"
    },
    "MappingSettings": {
      "InitFunction": "Activities.GetActivity(Property[ActivityId])",
      "Property[StartDate]": "Property[StartDate]",
      "Property[EndDate]": "Property[EndDate]",
    }
  }
}
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "InterfacesSettings",
  "additionalProperties": false,
  "properties": {
    "Activities": {
      "oneOf": [
        {
          "$ref": "#/definitions/InterfaceSettings"
        },
        {
          "type": "null"
        }
      ]
    },
    "Telemetry": {
      "oneOf": [
        {
          "$ref": "#/definitions/InterfaceSettings"
        },
        {
          "type": "null"
        }
      ]
    },
    "Gis": {
      "oneOf": [
        {
          "$ref": "#/definitions/InterfaceSettings"
        },
        {
          "type": "null"
        }
      ]
    },
    "WorkOrders": {
      "oneOf": [
        {
          "$ref": "#/definitions/InterfaceSettings"
        },
        {
          "type": "null"
        }
      ]
    },
    "Billing": {
      "oneOf": [
        {
          "$ref": "#/definitions/InterfaceSettings"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "definitions": {
    "InterfaceSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Enabled": {
          "type": "boolean"
        },
        "InvokeMode": {
          "oneOf": [
            {
              "$ref": "#/definitions/FileInvokeMode"
            }
          ]
        },
        "Area": {
          "type": [
            "null",
            "string"
          ]
        },
        "CsvSettings": {
          "oneOf": [
            {
              "$ref": "#/definitions/CsvSettings"
            },
            {
              "type": "null"
            }
          ]
        },
        "ExcelSettings": {
          "oneOf": [
            {
              "$ref": "#/definitions/ExcelSettings"
            },
            {
              "type": "null"
            }
          ]
        },
        "ExecutionSettings": {
          "oneOf": [
            {
              "$ref": "#/definitions/ProviderExecutionSettings"
            },
            {
              "type": "null"
            }
          ]
        },
        "MappingSettings": {
          "type": [
            "null",
            "object"
          ],
          "additionalProperties": {
            "type": "string"
          }
        }
      }
    },
    "FileInvokeMode": {
      "type": "string",
      "x-enumNames": [
        "Watcher",
        "Live",
        "Nightly",
        "None"
      ],
      "enum": [
        "Watcher",
        "Live",
        "Nightly",
        "None"
      ],
      "description": ""
    },
    "CsvSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Delimiter": {
          "type": [
            "null",
            "string"
          ]
        },
        "DateFormat": {
          "type": [
            "null",
            "string"
          ]
        },
        "Headers": {
          "oneOf": [
            {
              "$ref": "#/definitions/FileHeadersSettings"
            },
            {
              "type": "null"
            }
          ]
        },
        "Trim": {
          "type": "boolean"
        },
        "BatchSleep": {
          "type": [
            "null",
            "string"
          ],
          "format": "time-span"
        },
        "BatchSize": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32"
        },
        "MaxFileErrors": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32"
        }
      }
    },
    "FileHeadersSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "HasHeaders": {
          "type": "boolean"
        },
        "CustomHeaders": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ExcelSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Headers": {
          "oneOf": [
            {
              "$ref": "#/definitions/FileHeadersSettings"
            },
            {
              "type": "null"
            }
          ]
        },
        "Trim": {
          "type": "boolean"
        },
        "BatchSleep": {
          "type": [
            "null",
            "string"
          ],
          "format": "time-span"
        },
        "BatchSize": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32"
        },
        "MaxFileErrors": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32"
        }
      }
    },
    "ProviderExecutionSettings": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Attempts": {
          "type": "integer",
          "format": "int32"
        },
        "SleepInterval": {
          "type": "string",
          "format": "time-span"
        }
      }
    }
  }
}
RicoSuter commented 7 years ago

fixed with https://github.com/rsuter/VisualJsonEditor/commit/e66f76111e4ca5c1d75c869ecedc66185616ae92, v2.0