-
-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Labels
featureNew feature or requestNew feature or request
Description
Is your feature request related to a problem?
When generating classes from a JSON that has nested data, the root object gets generated with my defined class name, but any classes generated from properties of the root object are generated with just the property name.
Describe the feature you'd like
I would like to be able to provide a handler that can rewrite or prefix the generated class names.
What alternatives have you considered?
No response
Additional context
Input code:
var options = new Json2SharpOptions
{
TargetLanguage = Language.CSharp,
CSharpOptions = new Json2SharpCSharpOptions
{
IsSealed = false,
TargetType = CSharpObjectType.Class,
SerializationAttribute = CSharpSerializationAttribute.NewtonsoftJson
}
};
var rawJson = """{"users":[{"id":"be37a82a5e052a0482e021183f68dd8c","username":"Test 1","time":1751653380834},{"id":"c474b6fe22761d8c640b657c399e5aad","username":"Test 2","time":1751653386295}]}""";
var code = Json2Sharp.Parse("MessagePresenceList", rawJson, options);
Console.WriteLine(code);Output code:
using Newtonsoft.Json;
public class MessagePresenceList
{
[JsonProperty("users")]
public required Users[] Users { get; init; }
}
public class Users
{
[JsonProperty("id")]
public required string Id { get; init; }
[JsonProperty("username")]
public required string Username { get; init; }
[JsonProperty("time")]
public required long Time { get; init; }
}If the sub-classes are prefixed, expected output would be:
using Newtonsoft.Json;
public class MessagePresenceList
{
[JsonProperty("users")]
public required MessagePresenceListUsers[] Users { get; init; }
}
public class MessagePresenceListUsers
{
[JsonProperty("id")]
public required string Id { get; init; }
[JsonProperty("username")]
public required string Username { get; init; }
[JsonProperty("time")]
public required long Time { get; init; }
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew feature or requestNew feature or request