|
|
@ -184,7 +184,7 @@ namespace Squidex.Extensions.Actions.Kafka |
|
|
{ |
|
|
{ |
|
|
switch (value) |
|
|
switch (value) |
|
|
{ |
|
|
{ |
|
|
case JsonString s: |
|
|
case JsonString s when IsTypeOrUnionWith(schema, Schema.Type.String): |
|
|
return s.Value; |
|
|
return s.Value; |
|
|
case JsonNumber n when IsTypeOrUnionWith(schema, Schema.Type.Long): |
|
|
case JsonNumber n when IsTypeOrUnionWith(schema, Schema.Type.Long): |
|
|
return (long)n.Value; |
|
|
return (long)n.Value; |
|
|
@ -192,25 +192,55 @@ namespace Squidex.Extensions.Actions.Kafka |
|
|
return (float)n.Value; |
|
|
return (float)n.Value; |
|
|
case JsonNumber n when IsTypeOrUnionWith(schema, Schema.Type.Int): |
|
|
case JsonNumber n when IsTypeOrUnionWith(schema, Schema.Type.Int): |
|
|
return (int)n.Value; |
|
|
return (int)n.Value; |
|
|
case JsonNumber n: |
|
|
case JsonNumber n when IsTypeOrUnionWith(schema, Schema.Type.Double): |
|
|
return n.Value; |
|
|
return n.Value; |
|
|
case JsonBoolean b: |
|
|
case JsonBoolean b when IsTypeOrUnionWith(schema, Schema.Type.Boolean): |
|
|
return b.Value; |
|
|
return b.Value; |
|
|
case JsonObject o when (schema is MapSchema map): |
|
|
case JsonObject o when IsTypeOrUnionWith(schema, Schema.Type.Map): |
|
|
{ |
|
|
{ |
|
|
var mapResult = new Dictionary<string, object>(); |
|
|
var mapResult = new Dictionary<string, object>(); |
|
|
|
|
|
|
|
|
|
|
|
if (schema is UnionSchema union) |
|
|
|
|
|
{ |
|
|
|
|
|
var map = (MapSchema)union.Schemas.FirstOrDefault(x => x.Tag == Schema.Type.Map); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var (key, childValue) in o) |
|
|
|
|
|
{ |
|
|
|
|
|
mapResult.Add(key, GetValue(childValue, map?.ValueSchema)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (schema is MapSchema map) |
|
|
|
|
|
{ |
|
|
foreach (var (key, childValue) in o) |
|
|
foreach (var (key, childValue) in o) |
|
|
{ |
|
|
{ |
|
|
mapResult.Add(key, GetValue(childValue, map.ValueSchema)); |
|
|
mapResult.Add(key, GetValue(childValue, map?.ValueSchema)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return mapResult; |
|
|
return mapResult; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
case JsonObject o when (schema is RecordSchema record): |
|
|
case JsonObject o when IsTypeOrUnionWith(schema, Schema.Type.Record): |
|
|
{ |
|
|
{ |
|
|
var result = new GenericRecord(record); |
|
|
GenericRecord result = null; |
|
|
|
|
|
|
|
|
|
|
|
if (schema is UnionSchema union) |
|
|
|
|
|
{ |
|
|
|
|
|
var record = (RecordSchema)union.Schemas.FirstOrDefault(x => x.Tag == Schema.Type.Record); |
|
|
|
|
|
|
|
|
|
|
|
result = new GenericRecord(record); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var (key, childValue) in o) |
|
|
|
|
|
{ |
|
|
|
|
|
if (record != null && record.TryGetField(key, out var field)) |
|
|
|
|
|
{ |
|
|
|
|
|
result.Add(key, GetValue(childValue, field.Schema)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (schema is RecordSchema record) |
|
|
|
|
|
{ |
|
|
|
|
|
result = new GenericRecord(record); |
|
|
|
|
|
|
|
|
foreach (var (key, childValue) in o) |
|
|
foreach (var (key, childValue) in o) |
|
|
{ |
|
|
{ |
|
|
@ -219,18 +249,31 @@ namespace Squidex.Extensions.Actions.Kafka |
|
|
result.Add(key, GetValue(childValue, field.Schema)); |
|
|
result.Add(key, GetValue(childValue, field.Schema)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
case JsonArray a when (schema is ArraySchema array): |
|
|
case JsonArray a when IsTypeOrUnionWith(schema, Schema.Type.Array): |
|
|
{ |
|
|
{ |
|
|
var result = new List<object>(); |
|
|
var result = new List<object>(); |
|
|
|
|
|
|
|
|
|
|
|
if (schema is UnionSchema union) |
|
|
|
|
|
{ |
|
|
|
|
|
var arraySchema = (ArraySchema)union.Schemas.FirstOrDefault(x => x.Tag == Schema.Type.Array); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in a) |
|
|
|
|
|
{ |
|
|
|
|
|
result.Add(GetValue(item, arraySchema?.ItemSchema)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (schema is ArraySchema array) |
|
|
|
|
|
{ |
|
|
foreach (var item in a) |
|
|
foreach (var item in a) |
|
|
{ |
|
|
{ |
|
|
result.Add(GetValue(item, array.ItemSchema)); |
|
|
result.Add(GetValue(item, array.ItemSchema)); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return result.ToArray(); |
|
|
return result.ToArray(); |
|
|
} |
|
|
} |
|
|
|