ABAP - Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and JSON →  Transformations for JSON →  asJSON - Canonical JSON Representation →  asJSON - Mapping of ABAP Data Types →  asJSON - Mapping of Reference Variables and Objects → 

asJSON - Instances of Classes

To transform classes to JSON using the statement CALL TRANSFORMATION, or to create classes from JSON data, their classes must implement the interface IF_SERIALIZABLE_OBJECT. The instance of a class (object) is displayed as an object component of the object %heap as follows:

"key":{ "%type":"class",
        "%val":{ "part":{ "%classVersion":"...",
                          "name":...
                          ...
                        }
                 ...
               }
      }

The name key is the key used to reference the object. The value of key is itself an object whose object components represent the class and the attributes of the referenced ABAP object.

The tag interface IF_SERIALIZABLE_OBJECT has the same meaning for JSON as for asXML. This means it defines which attributes of a class are serialized and helper methods can be implement that modify the behavior (see the example).

Executable Example

asJSON for Object References