All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.server.resp.serialization.JavaObjectSerializer Maven / Gradle / Ivy

There is a newer version: 15.1.4.Final
Show newest version
package org.infinispan.server.resp.serialization;

/**
 * Base class for serializing custom Java objects into the final RESP3 format.
 *
 * 

* Extend this class to add support to a Java object type. This mechanism is useful when handling methods that return * an object instead of the primitive values. Also, nested data structures with heterogeneous elements must provide * an instance of {@link JavaObjectSerializer} to correctly the elements. *

* * An example of how to utilize the serializer when handling a heterogeneous map. The map contains string and integer * values. * *
 * {@code
 * class MyCustomSerializer extends JavaObjectSerializer> {
 *
 *    @Override
 *    public void accept(Date date, ByteBufPool alloc) {
 *       // Write map prefix, then the keys and values.
 *       // Utilize the base pieces from the Resp3Response class to write the primitive values.
 *    }
 *
 *    public static void main(String[] args) {
 *       ByteBufPool alloc = ...;
 *       Map map = Map.of("k1", "v1", "k2", 42);
 *       Resp3Response.write(map, alloc, new MyCustomSerializer());
 *       Resp3Response.map(map, alloc, new MyCustomSerializer());
 *    }
 * }
 * }
 * 
* *

* The caller can also provide a lambda that receives the response and the {@link org.infinispan.server.resp.ByteBufPool} * as arguments for serialization. If a serializer is stateless, it can be a singleton and shared for all invocations. *

* * @param The type of object the instance is handling. This type filter the objects during runtime, accepting types * of T and subclasses. */ @FunctionalInterface public interface JavaObjectSerializer extends ResponseSerializer { @Override default boolean test(Object object) { return true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy