Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.common.base.Supplier;
- import com.fasterxml.jackson.annotation.JsonProperty;
- import com.fasterxml.jackson.annotation.JsonTypeInfo;
- /**
- * Acts as a {@link com.hazelcast.nio.DataSerializable DataSerializable} wrapper
- * for type that might not have default constructor.
- */
- public final class SerializableHolder<T> extends JsonDataSerializable implements Supplier<T> {
- /**
- * Wraps a value to make it serializable.
- */
- public static <T> SerializableHolder<T> of(T contents) {
- return new SerializableHolder<T>(contents);
- }
- /**
- * Default constructor needed in order to be
- * {@link com.hazelcast.nio.DataSerializable DataSerializable}.
- */
- public SerializableHolder() {
- // Nothing to do.
- }
- /**
- * Retrieve the wrapped value.
- */
- @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS)
- @JsonProperty("x")
- public T get() {
- return contents;
- }
- SerializableHolder(T contents) {
- this.contents = contents;
- }
- @JsonProperty("x") private T contents;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement