Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a1a4d98
test: Add tests for serialization of non-serialized interface fields
IvanMurzak Dec 24, 2025
cee33d7
feat: Enhance serialization handling by excluding NonSerialized attri…
IvanMurzak Dec 24, 2025
390debd
feat: Improve serialization robustness by handling inaccessible field…
IvanMurzak Dec 24, 2025
06ff3c0
feat: Refactor serialization error handling and add utility for retri…
IvanMurzak Dec 25, 2025
4d1ed5f
refactor: Clean up using directives and improve readability of GetDee…
IvanMurzak Dec 25, 2025
75553e6
fix: Update serialization error logging to use GetBaseException and r…
IvanMurzak Dec 25, 2025
956cdbc
fix: Simplify variable declaration and improve logging for inaccessib…
IvanMurzak Dec 25, 2025
1ed3526
Add custom JSON converters for various types
IvanMurzak Dec 26, 2025
31414d6
fix: Improve readability by simplifying parameter passing in serializ…
IvanMurzak Dec 26, 2025
e2ae538
fix: Rename class for clarity and update related test references
IvanMurzak Dec 26, 2025
a524022
fix: Enhance null handling and improve type safety in JSON converters
IvanMurzak Dec 26, 2025
d1b2a1c
fix: Simplify variable declarations in ComplexJsonConverter and IPEnd…
IvanMurzak Dec 26, 2025
e780dbe
fix: Enhance null handling in JSON converters and improve field/prope…
IvanMurzak Dec 26, 2025
c327a69
fix: Remove unused using directives and update type handling in test …
IvanMurzak Dec 26, 2025
db79642
fix: Enhance null handling in BigIntegerJsonConverter to return defau…
IvanMurzak Dec 26, 2025
63349e9
fix: Enhance null handling and improve type safety in JSON converters
IvanMurzak Dec 26, 2025
490e0b6
Add comprehensive JSON converter tests for various types
IvanMurzak Dec 26, 2025
bdd0a81
feat: Add comprehensive tests for additional JSON converters includin…
IvanMurzak Dec 26, 2025
3b6b9e1
Refactor JSON Converter Tests
IvanMurzak Dec 26, 2025
a9c7d82
feat: Add comprehensive tests for JSON converters including Bool, Cha…
IvanMurzak Dec 26, 2025
23d4842
fix: Update null checks for improved readability in JSON converters
IvanMurzak Dec 26, 2025
47b6a5d
fix: Enhance security and error handling in JSON converters for Assem…
IvanMurzak Dec 26, 2025
a3f54af
fix: Remove unused namespace import in HalfJsonConverter
IvanMurzak Dec 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
var reflector = new Reflector();
var methodInfo = typeof(Sample).GetMethod(nameof(Sample.Command));

var argumentsSchema = reflector.GetArgumentsSchema(methodInfo);
var outputSchema = reflector.GetReturnSchema(methodInfo);
var argumentsSchema = reflector.GetArgumentsSchema(methodInfo!);
var outputSchema = reflector.GetReturnSchema(methodInfo!);

Console.WriteLine("Arguments Schema:");
Console.WriteLine(argumentsSchema.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine("Output Schema:");
Console.WriteLine(outputSchema.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine(outputSchema?.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));

var schemaJson = reflector.GetSchema<GameState<PlayerProfile>>();

Expand All @@ -44,8 +44,8 @@ public class Data
{
public int? optionalInt;
[Description("THIS IS THE DEMO DESCRIPTION.")]
public string address;
public List<Data> list; // recursive
public string address = null!;
public List<Data> list = null!; // recursive
}

public struct Result
Expand Down Expand Up @@ -74,15 +74,15 @@ public struct GeoPoint
public class PlayerProfile
{
public Guid Id { get; set; }
public string Username { get; set; }
public string[] Badges { get; set; } // Array
public Dictionary<string, int> Stats { get; set; } // Dictionary
public string Username { get; set; } = null!;
public string[] Badges { get; set; } = null!; // Array
public Dictionary<string, int> Stats { get; set; } = null!; // Dictionary
}

// A generic wrapper (common in Game State or API responses)
public class GameState<T>
{
public long Timestamp { get; set; }
public T Player { get; set; }
public List<GeoPoint> Checkpoints { get; set; } // List of Structs
public T Player { get; set; } = default!;
public List<GeoPoint> Checkpoints { get; set; } = null!; // List of Structs
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Text.Json;
using Xunit;
using Xunit.Abstractions;

namespace com.IvanMurzak.ReflectorNet.Tests.JsonConverterTests
{
/// <summary>
/// Tests for Bool and Char JSON converters
/// </summary>
public class BasicTypesConverterTests : BaseTest
{
private readonly Reflector _reflector;

public BasicTypesConverterTests(ITestOutputHelper output) : base(output)
{
_reflector = new Reflector();
}

#region BoolJsonConverter Tests

[Fact]
public void Bool_Serialize_True()
{
var value = true;
var json = _reflector.JsonSerializer.Serialize(value);
Assert.Equal("true", json);
}

[Fact]
public void Bool_Serialize_False()
{
var value = false;
var json = _reflector.JsonSerializer.Serialize(value);
Assert.Equal("false", json);
}

[Fact]
public void Bool_Deserialize_True()
{
var json = "true";
var result = _reflector.JsonSerializer.Deserialize<bool>(json);
Assert.True(result);
}

[Fact]
public void Bool_Deserialize_False()
{
var json = "false";
var result = _reflector.JsonSerializer.Deserialize<bool>(json);
Assert.False(result);
}

[Fact]
public void Bool_Deserialize_FromString()
{
var json = "\"true\"";
var result = _reflector.JsonSerializer.Deserialize<bool>(json);
Assert.True(result);
}

#endregion

#region CharJsonConverter Tests

[Fact]
public void Char_Serialize_Value()
{
var value = 'A';
var json = _reflector.JsonSerializer.Serialize(value);
Assert.Equal("\"A\"", json);
}

[Fact]
public void Char_Deserialize_Value()
{
var json = "\"B\"";
var result = _reflector.JsonSerializer.Deserialize<char>(json);
Assert.Equal('B', result);
}

[Fact]
public void Char_Deserialize_FromNumber()
{
var json = "65";
var result = _reflector.JsonSerializer.Deserialize<char>(json);
Assert.Equal('A', result);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Numerics;
using System.Text.Json;
using Xunit;
using Xunit.Abstractions;

namespace com.IvanMurzak.ReflectorNet.Tests.JsonConverterTests
{
/// <summary>
/// Tests for BigInteger JSON converter
/// </summary>
public class BigIntegerConverterTests : BaseTest
{
private readonly Reflector _reflector;

public BigIntegerConverterTests(ITestOutputHelper output) : base(output)
{
_reflector = new Reflector();
}

#region BigIntegerJsonConverter Tests

[Fact]
public void BigInteger_Serialize_Value()
{
var value = BigInteger.Parse("123456789012345678901234567890");
var json = _reflector.JsonSerializer.Serialize(value);
_output.WriteLine($"BigInteger value: {json}");
Assert.Contains("123456789012345678901234567890", json);
}

[Fact]
public void BigInteger_Serialize_Zero()
{
var value = BigInteger.Zero;
var json = _reflector.JsonSerializer.Serialize(value);
_output.WriteLine($"BigInteger zero: {json}");
Assert.Equal("\"0\"", json);
}

[Fact]
public void BigInteger_Serialize_Negative()
{
var value = BigInteger.Parse("-98765432109876543210");
var json = _reflector.JsonSerializer.Serialize(value);
_output.WriteLine($"BigInteger negative: {json}");
Assert.Contains("-98765432109876543210", json);
}

[Fact]
public void BigInteger_Deserialize_FromNumber()
{
var json = "12345678901234567890";
var result = _reflector.JsonSerializer.Deserialize<BigInteger>(json);
_output.WriteLine($"BigInteger from number: {result}");
Assert.Equal(BigInteger.Parse("12345678901234567890"), result);
}

[Fact]
public void BigInteger_Deserialize_FromString()
{
var json = "\"999999999999999999999999999999\"";
var result = _reflector.JsonSerializer.Deserialize<BigInteger>(json);
_output.WriteLine($"BigInteger from string: {result}");
Assert.Equal(BigInteger.Parse("999999999999999999999999999999"), result);
}

[Fact]
public void BigInteger_RoundTrip()
{
var original = BigInteger.Pow(2, 100);
var json = _reflector.JsonSerializer.Serialize(original);
var deserialized = _reflector.JsonSerializer.Deserialize<BigInteger>(json);
_output.WriteLine($"BigInteger roundtrip: {original} -> {json} -> {deserialized}");
Assert.Equal(original, deserialized);
}

#endregion
}
}
Loading