Browse Source

Use concrete json types.

pull/525/head
Sebastian 6 years ago
parent
commit
3b08920c1f
  1. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/ConvertContent/ValueConverters.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs
  3. 6
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/JsonMapper.cs
  4. 14
      backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/JsonValueConverter.cs

2
backend/src/Squidex.Domain.Apps.Core.Operations/ConvertContent/ValueConverters.cs

@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Core.ConvertContent
{ {
return (value, field, parent) => return (value, field, parent) =>
{ {
if (field is IField<JsonFieldProperties> && value is JsonScalar<string> s) if (field is IField<JsonFieldProperties> && value is JsonString s)
{ {
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(s.Value)); var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(s.Value));

2
backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueGenerator.cs

@ -72,7 +72,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues
private static bool ShouldApplyDefaultValue(IField field, IJsonValue value) private static bool ShouldApplyDefaultValue(IField field, IJsonValue value)
{ {
return value.Type == JsonValueType.Null || (field is IField<StringFieldProperties> && value is JsonScalar<string> s && string.IsNullOrEmpty(s.Value)); return value.Type == JsonValueType.Null || (field is IField<StringFieldProperties> && value is JsonString s && string.IsNullOrEmpty(s.Value));
} }
} }
} }

6
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/JsonMapper.cs

@ -26,11 +26,11 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
{ {
case JsonNull _: case JsonNull _:
return JsValue.Null; return JsValue.Null;
case JsonScalar<string> s: case JsonString s:
return new JsString(s.Value); return new JsString(s.Value);
case JsonScalar<bool> b: case JsonBoolean b:
return new JsBoolean(b.Value); return new JsBoolean(b.Value);
case JsonScalar<double> b: case JsonNumber b:
return new JsNumber(b.Value); return new JsNumber(b.Value);
case JsonObject obj: case JsonObject obj:
return FromObject(obj, engine); return FromObject(obj, engine);

14
backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/JsonValueConverter.cs

@ -50,7 +50,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
public (object? Result, JsonError? Error) Visit(IField<BooleanFieldProperties> field) public (object? Result, JsonError? Error) Visit(IField<BooleanFieldProperties> field)
{ {
if (value is JsonScalar<bool> b) if (value is JsonBoolean b)
{ {
return (b.Value, null); return (b.Value, null);
} }
@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
public (object? Result, JsonError? Error) Visit(IField<NumberFieldProperties> field) public (object? Result, JsonError? Error) Visit(IField<NumberFieldProperties> field)
{ {
if (value is JsonScalar<double> n) if (value is JsonNumber n)
{ {
return (n.Value, null); return (n.Value, null);
} }
@ -70,7 +70,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
public (object? Result, JsonError? Error) Visit(IField<StringFieldProperties> field) public (object? Result, JsonError? Error) Visit(IField<StringFieldProperties> field)
{ {
if (value is JsonScalar<string> s) if (value is JsonString s)
{ {
return (s.Value, null); return (s.Value, null);
} }
@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
} }
} }
if (geolocation.TryGetValue("latitude", out var latValue) && latValue is JsonScalar<double> latNumber) if (geolocation.TryGetValue("latitude", out var latValue) && latValue is JsonNumber latNumber)
{ {
var lat = latNumber.Value; var lat = latNumber.Value;
@ -127,7 +127,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
return (null, new JsonError("Invalid json type, expected latitude/longitude object.")); return (null, new JsonError("Invalid json type, expected latitude/longitude object."));
} }
if (geolocation.TryGetValue("longitude", out var lonValue) && lonValue is JsonScalar<double> lonNumber) if (geolocation.TryGetValue("longitude", out var lonValue) && lonValue is JsonNumber lonNumber)
{ {
var lon = lonNumber.Value; var lon = lonNumber.Value;
@ -160,7 +160,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
foreach (var item in array) foreach (var item in array)
{ {
if (item is JsonScalar<string> s && Guid.TryParse(s.Value, out var guid)) if (item is JsonString s && Guid.TryParse(s.Value, out var guid))
{ {
result.Add(guid); result.Add(guid);
} }
@ -188,7 +188,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent
{ {
result.Add(null); result.Add(null);
} }
else if (item is JsonScalar<string> s) else if (item is JsonString s)
{ {
result.Add(s.Value); result.Add(s.Value);
} }

Loading…
Cancel
Save