PHP Classes

File: doc/

Recommend this page to a friend!
  Classes of Julian Finkler   JSON Object Mapper   doc/   Download  
File: doc/
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: JSON Object Mapper
Create objects of classes mapped from JSON strings
Author: By
Last change:
Date: 6 years ago
Size: 850 bytes


Class file image Download

Mapping Alternative Property Names

? Go to index

Sometimes it is useful or required to map the property names from the json to another property name in the class object. (e.g. the property uses incompatible characters or the naming is not good):

    "first name": "Pete",
    "lastname": "Peterson",
    "foo*bar": "baz"

In this case you can use the name argument in the annotation to refer the name of the property in the json object


class User {
    / @JsonField(name="first name") */
    public $firstname;

    / @JsonField(name="lastname") */
    public $surname;

    / @JsonField(name="foobar")/
    public $aFunnyMessage;

The mapped object would be something like that:

User Object
    [firstname] => Pete
    [surname] => Peterson
    [aFunnyMessage] => baz