Skip to content

[Feature request] Attribute similar to PhpIgnore but more like "ignore if null" #33

@mrhappyasthma

Description

@mrhappyasthma

I'm looking to have an object that I'm using as a data model which will eventually be serialized. But I want to mark some fields as ignored, but not PhpIgnore (which skips it unconditionally) but something along the lines of "Ignore, but only if it's null".

For example:

public class MyClass {
    [PhpProperty("Foo")]
    public string Foo {get;set;};
    
    // ... Other stuff
}

If Foo is null, it will serialize along the lines of: s:3:"Foo";N;

I would like this output to be skipped entirely if it is null.

Maybe something like

public class MyClass {
    [PhpProperty("Foo")]
    [PhpIgnoreNull]   // Or similar
    public string Foo {get;set;};
    
    // ... Other stuff
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions