use of org.infinispan.commons.dataconversion.Transcoder in project infinispan by infinispan.
the class ScriptConversions method convertToRequestType.
public Object convertToRequestType(Object obj, MediaType objType, MediaType requestType) {
if (obj == null)
return null;
if (requestType.equals(MediaType.MATCH_ALL))
return obj;
// Older HR clients do not send request type and assume the script metadata type is the output type
MediaType outputFormat = requestType.match(MediaType.APPLICATION_UNKNOWN) ? objType : requestType;
OutputFormatter outputFormatter = formatterByMediaType.get(outputFormat.getTypeSubtype());
if (obj instanceof Collection) {
if (outputFormatter != null) {
return outputFormatter.formatCollection((Collection<?>) obj, objType, requestType);
}
}
Transcoder transcoder = encoderRegistry.getTranscoder(objType, requestType);
return transcoder.transcode(obj, objType, requestType);
}
use of org.infinispan.commons.dataconversion.Transcoder in project infinispan by infinispan.
the class LifecycleCallbacks method cacheManagerStarting.
@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, new PersistenceContextInitializerImpl());
ClassAllowList classAllowList = gcr.getComponent(EmbeddedCacheManager.class).getClassAllowList();
ClassLoader classLoader = globalConfiguration.classLoader();
EncoderRegistry encoderRegistry = gcr.getComponent(EncoderRegistry.class);
JsonTranscoder jsonTranscoder = new JsonTranscoder(classLoader, classAllowList);
encoderRegistry.registerTranscoder(jsonTranscoder);
registerXmlTranscoder(encoderRegistry, classLoader, classAllowList);
// Allow transcoding between JBoss Marshalling and JSON
if (encoderRegistry.isConversionSupported(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_JBOSS_MARSHALLING)) {
Transcoder jbossMarshallingTranscoder = encoderRegistry.getTranscoder(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_JBOSS_MARSHALLING);
encoderRegistry.registerTranscoder(new TwoStepTranscoder(jbossMarshallingTranscoder, jsonTranscoder));
}
}
use of org.infinispan.commons.dataconversion.Transcoder in project infinispan by infinispan.
the class LifecycleManager method buildQuerySerializers.
private QuerySerializers buildQuerySerializers(ComponentRegistry cr, MediaType storageMediaType) {
EncoderRegistry encoderRegistry = cr.getGlobalComponentRegistry().getComponent(EncoderRegistry.class);
QuerySerializers querySerializers = new QuerySerializers();
DefaultQuerySerializer defaultQuerySerializer = new DefaultQuerySerializer(encoderRegistry);
querySerializers.addSerializer(MediaType.MATCH_ALL, defaultQuerySerializer);
if (encoderRegistry.isConversionSupported(storageMediaType, APPLICATION_JSON)) {
Transcoder jsonStorage = encoderRegistry.getTranscoder(APPLICATION_JSON, storageMediaType);
querySerializers.addSerializer(APPLICATION_JSON, new JsonQuerySerializer(storageMediaType, jsonStorage));
}
return querySerializers;
}
use of org.infinispan.commons.dataconversion.Transcoder in project infinispan by infinispan.
the class DefaultQuerySerializer method encodeQueryResponse.
public byte[] encodeQueryResponse(Object queryResponse, MediaType destinationType) {
MediaType destination = destinationType;
// QueryResponses are sent in 'unwrapped' protobuf format
if (destinationType.match(APPLICATION_PROTOSTREAM))
destination = PROTOSTREAM_UNWRAPPED;
Transcoder transcoder = encoderRegistry.getTranscoder(APPLICATION_OBJECT, destinationType);
return (byte[]) transcoder.transcode(queryResponse, APPLICATION_OBJECT, destination);
}
Aggregations