Skip to content
JonathanO edited this page Oct 14, 2012 · 3 revisions

JsonAnySetter

Method annotation to handle unknown properties when deserializing. The AnySetter method is expected to store the unknowns when deserializing. Having an AnySetter will prevent warnings being lobbed for unknown properties, instead they'll be passed to your AnySetter.

A method annotated with @JsonAnySetter must take exactly two parameters, the key and the value to store.

There can only be one @JsonAnySetter per class.

This is commonly used with @JsonAnyGetter

Parameters

There aren't any.

Example

class Foo {

    private $anyStuff = array();

    /**
     * @JsonAnySetter
     */
    function amSetter($key, $value) {
        $this->anyStuff[$key] = $value;
    }

    /**
     * @JsonAnyGetter
     */
    function getStuff() {
        return $this->anyStuff;
    }
}
Clone this wiki locally