Skip to content
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

How to ignore the property using JsonIgnore #233

Open
wreuel opened this issue Feb 24, 2022 · 1 comment
Open

How to ignore the property using JsonIgnore #233

wreuel opened this issue Feb 24, 2022 · 1 comment

Comments

@wreuel
Copy link

wreuel commented Feb 24, 2022

Hi there, I'm really happy with the project, but I do have a question, I'm using the fluent configuration, and I want to Ignore the property that has the attribut JsonIgnore:

public class CreateRequest
{
    public CreateRequest()
    {
    }
    public string Url { get; set; }
    [JsonIgnore]
    public string? CreatedBy { get; set; }
}

At the moment the result is:

export interface CreateRequest
{
	createdBy: string;
	url: string;
}

I wish I could have like:

export interface CreateRequest
{
	url: string;
}

without needing to add the [TsIgnore]. Is that possible? I read the documentation, and didn't find how to do it by there.

@torben-struct
Copy link

Not an exact answer, but you can use WithPublicProperties and pass a method to filter properties.

Pseudo/snippet untested code:

builder.ExportAsClasses(myTypes, ceb => ceb.WithPublicProperties(ConfigureClassProperties))

private static void ConfigureClassProperties(PropertyExportBuilder propertyExportBuilder)
{
   if (propertyExportBuilder.Member.GetCustomAttributes<Newtonsoft.Json.JsonIgnoreAttribute>().Any())
   {
      propertyExportBuilder.Ignore();
   }
}

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