Skip to content

Commit

Permalink
(cake-contribGH-400) Update LitJson to 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Jul 4, 2021
1 parent 5186a2d commit bd11ee2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/Cake.Issues.Reporting.Generic/LitJson/JsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ private static object ReadValue (Type inst_type, JsonReader reader)
elem_type = inst_type.GetElementType ();
}

list.Clear();

while (true) {
object item = ReadValue (elem_type, reader);
if (item == null && reader.Token == JsonToken.ArrayEnd)
Expand Down Expand Up @@ -680,6 +682,11 @@ private static void RegisterBaseImporters ()
RegisterImporter (base_importers_table, typeof (double),
typeof (decimal), importer);

importer = delegate (object input) {
return Convert.ToSingle((double)input);
};
RegisterImporter(base_importers_table, typeof(double),
typeof(float), importer);

importer = delegate (object input) {
return Convert.ToUInt32 ((long) input);
Expand Down Expand Up @@ -750,6 +757,12 @@ private static void WriteValue (object obj, JsonWriter writer,
return;
}

if (obj is Single)
{
writer.Write((float)obj);
return;
}

if (obj is Int32) {
writer.Write ((int) obj);
return;
Expand Down Expand Up @@ -785,10 +798,13 @@ private static void WriteValue (object obj, JsonWriter writer,
return;
}

if (obj is IDictionary) {
if (obj is IDictionary dictionary) {
writer.WriteObjectStart ();
foreach (DictionaryEntry entry in (IDictionary) obj) {
writer.WritePropertyName ((string) entry.Key);
foreach (DictionaryEntry entry in dictionary) {
var propertyName = entry.Key is string key ?
key
: Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
writer.WritePropertyName (propertyName);
WriteValue (entry.Value, writer, writer_is_private,
depth + 1);
}
Expand Down Expand Up @@ -819,10 +835,20 @@ private static void WriteValue (object obj, JsonWriter writer,
if (obj is Enum) {
Type e_type = Enum.GetUnderlyingType (obj_type);

if (e_type == typeof (long)
|| e_type == typeof (uint)
|| e_type == typeof (ulong))
if (e_type == typeof (long))
writer.Write ((long) obj);
else if (e_type == typeof (uint))
writer.Write ((uint) obj);
else if (e_type == typeof (ulong))
writer.Write ((ulong) obj);
else if (e_type == typeof(ushort))
writer.Write ((ushort)obj);
else if (e_type == typeof(short))
writer.Write ((short)obj);
else if (e_type == typeof(byte))
writer.Write ((byte)obj);
else if (e_type == typeof(sbyte))
writer.Write ((sbyte)obj);
else
writer.Write ((int) obj);

Expand Down
11 changes: 11 additions & 0 deletions src/Cake.Issues.Reporting.Generic/LitJson/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ public void Write (double number)
context.ExpectingValue = false;
}

public void Write(float number)
{
DoValidation(Condition.Value);
PutNewline();

string str = Convert.ToString(number, number_format);
Put(str);

context.ExpectingValue = false;
}

public void Write (int number)
{
DoValidation (Condition.Value);
Expand Down

0 comments on commit bd11ee2

Please sign in to comment.