Skip to content

Serializing Guid type throws JsonException #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
srprash opened this issue Jul 29, 2021 · 1 comment
Open

Serializing Guid type throws JsonException #127

srprash opened this issue Jul 29, 2021 · 1 comment

Comments

@srprash
Copy link

srprash commented Jul 29, 2021

Hi,
Looking at this issue opened with our repo, I realized that LitJSON doesn't handle serializing Guid type very well and throws the following error:

Unhandled exception. LitJson.JsonException: Max allowed object depth reached while trying to export from type System.Guid
   at LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in C:\projects\litjson\src\LitJson\JsonMapper.cs:line 725
   at LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in C:\projects\litjson\src\LitJson\JsonMapper.cs:line 861
   at LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in C:\projects\litjson\src\LitJson\JsonMapper.cs:line 861
   at LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in C:\projects\litjson\src\LitJson\JsonMapper.cs:line 861

More details along with a repro code are on the issue. Let me know if there's a way to handle Guid without special casing. Would be happy to do a PR. Thanks!

@kdprince
Copy link

kdprince commented Aug 5, 2021

I believe the general case involves models that contain public properties that are recursive.

Here's a System.Runtime type that defines a recursive structure

public readonly struct DateTimeOffset 
{
  /// Recursive properties below
   public static DateTimeOffset UtcNow { get; }
   public static DateTimeOffset Now { get; }

}

Example:

 public class ModelWithSelfReferenceProp
  {
      public ModelWithSelfReferenceProp()
      {
          RightNow = DateTime.Now;
      }
      public DateTimeOffset RightNow { get; }
  }

  [Fact]
  public void TestShouldNotThrowError()
  {
      var model = new ModelWithSelfReferenceProp();
      
      JsonMapper.ToJson(model);
      Assert.NotNull(model);
  }

Max allowed object depth reached while trying to export from type System.DateTimeOffset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants