The RFC7515 (JWS) and RFC7516 (JWE) introduce several serialization modes.
Compact
JSON Flattened
JSON General
The Compact mode is most know and commonly used as it is compact and URL safe i.e. it is designed for web context. JSON Flattened and General are not URL safe, but provides features that may fit on your application context.
JWS Serialization
JWS Compact
This serialization mode is probably the one you know the most. It it a string composed of three parts encoded in Base64 Url Safe and separated by a dot (.).
The serializer class is Jose\Component\Signature\Serializer\CompactSerializer. The associated name is jws_compact.
The serializer manager can be helpful when your application deals more than one serialization mode.
<?phprequire_once'vendor/autoload.php';useJose\Component\Signature\Serializer;$manager =Serializer\JWSSerializerManager::create([newSerializer\CompactSerializer(),newSerializer\JSONFlattenedSerializer(),newSerializer\JSONGeneralSerializer(),]);// Serializes the second signature (index = 1) of the variable $jws (JWS object) into JSON Flattened serialization mode.$token = $manager->serialize('jws_json_flattened', $jws,1);// Retrieve the JWS object from a token$jws = $manager->unserialize($token);
JWE Serialization
JWE Compact
This serialization mode is probably the one you know the most. It it a string composed of five parts encoded in Base64 Url Safe and separated by a dot (.).
The serializer class is Jose\Component\Encryption\Serializer\CompactSerializer. The associated name is jwe_compact.
The serializer manager can be helpful when your application deals more than one serialization mode.
<?phprequire_once'vendor/autoload.php';useJose\Component\Encryption\Serializer;$manager =Serializer\JWESerializerManager::create([newSerializer\CompactSerializer(),newSerializer\JSONFlattenedSerializer(),newSerializer\JSONGeneralSerializer(),]);// Serializes the second recipient (index = 1) of the variable $jwe (JWE object) into JSON Flattened serialization mode.$token = $manager->serialize('jwe_json_flattened', $jwe,1);// Retrieve the JWE object from a token$jwe = $manager->unserialize($token);