Skip to content
JonathanO edited this page Apr 2, 2013 · 2 revisions

JsonInclude

Specifies what values should be included when serializing to JSON. Can be specified on a class, or property/method basis.

Parameters

  1. value (integer) A value from the Include enum.

Enums

  • Include
    • ALWAYS: always include this property
    • NON_DEFAULT: Not implemented.
    • NON_EMPTY: include if not empty()
    • NON_NULL: include if !is_null()

Examples

Don't include null properties in the serialized form of this object. Additionally the foo field should not be included if it's considered empty().

For Doctrine driven annotations:

<?
/**
 * @JsonInclude(JsonInclude::INCLUDE_NON_NULL)
 */
class Baz {

/**
 * @JsonProperty
 * @JsonInclude(JsonInclude::INCLUDE_NON_EMPTY)
 */
public $foo;

For Weasel annotations:

<?
/**
 * @JsonInclude(JsonInclude.Include.NON_NULL)
 */
class Baz {

/**
 * @JsonProperty
 * @JsonInclude(JsonInclude.Include.NON_EMPTY)
 */
public $foo;

Back to Annotations list

Clone this wiki locally