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

Question: When using model entity classes how to limit fields which are sent during POST/PATCH but are still getting mapped during GET queries #907

Open
swidz opened this issue Jun 17, 2023 · 0 comments

Comments

@swidz
Copy link

swidz commented Jun 17, 2023

Hi,

I am struggling how to limit the payload only to fields only there were set (skip default, null fields).
If I use JsonIgnore fields are being ignored during POST but also during GET


public class MyEntity
{
public Guid Id { get; set; } //Key
public Code {get; set; }  //Alternate Key
public Name { get; set;}
}

var entity = new MyEntity
{
Code = "ABC",
Name = "New ABC"
};

await client.For<MyEntity>.Set(entity).InsertEntryAsync();

I would like to achieve JSON beeing generated is something like:

{
"@odata.type":"#MyEntity",
"Code":"ABC",
"Name":"New ABC"
}

instead what gets generated is

{
"@odata.type":"#MyEntity",
"Id":"00000000-0000-0000-0000-000000000000",
"Code":"ABC",
"Name":"New ABC"
}

I was trying to use JSONIgnore with condition [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
But is not currently supported.
Perhaps there is another way??

Regards,
Sebastian

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

1 participant