[id='converting-data-on-demand_{context}']
= Converting data on demand with embedded caches
Embedded caches have a default request encoding of `application/x-java-object` and a storage encoding that corresponds to the media type that you configure for the cache.
This means that {brandname} marshalls POJOs from the application to the storage encoding for the cache and then returns POJOs back to the application.
In some complex scenarios you can use the `AdvancedCache` API to change the default conversion to and from POJOs to other encodings.

The following example uses the `withMediaType()` method to return values as `application/json` on demand.

.Advanced cache with MediaType
[source,java,options="nowrap",subs=attributes+]
----
include::code_examples/EncodeMediaTypeOverride.java[]
----

.Value returned in JSON format
[source,json,options="nowrap",subs=attributes+]
----
include::json/john_doe.json[]
----

[role="_additional-resources"]
.Additional resources
* link:../../apidocs/org/infinispan/AdvancedCache.html[org.infinispan.AdvancedCache]
