ABAP - Keyword Documentation →  ABAP - Programming Language →  Data Interfaces and Communication Interfaces →  ABAP and JSON →  JSON - Transformations →  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 represented 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. In addition, helper methods can be implemented that adjust behavior (see the example).

Executable Example

asJSON for Object References