Class RuntimeEnv
- java.lang.Object
-
- io.protostuff.runtime.RuntimeEnv
-
public final class RuntimeEnv extends java.lang.Object
The runtime environment.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
RuntimeEnv.Android2Instantiator<T>
(package private) static class
RuntimeEnv.DefaultInstantiator<T>
static class
RuntimeEnv.Instantiator<T>
-
Field Summary
Fields Modifier and Type Field Description static boolean
ALWAYS_USE_SUN_REFLECTION_FACTORY
If true, the constructor will always be obtained fromReflectionFactory.newConstructorFromSerialization
.static boolean
AUTO_LOAD_POLYMORPHIC_CLASSES
Enabled by default.static boolean
COLLECTION_SCHEMA_ON_REPEATED_FIELDS
On repeated fields, the List/Collection itself is not serialized (only its values).static boolean
ENUMS_BY_NAME
Returns true if serializing enums by name is activated.static IdStrategy
ID_STRATEGY
static boolean
JAVA_9_AND_ABOVE
true
for JDKs 9, 10, 11, etc;false
for 1.8 and below.static boolean
MORPH_COLLECTION_INTERFACES
Disabled by default.static boolean
MORPH_MAP_INTERFACES
Disabled by default.static boolean
MORPH_NON_FINAL_POJOS
Disabled by default.static boolean
NEVER_USE_SUN_REFLECTION_FACTORY
If true, the constructor will never be obtained fromReflectionFactory.newConstructorFromSerialization
.(package private) static java.lang.reflect.Method
newInstanceFromObjectInputStream
(package private) static java.lang.reflect.Constructor<java.lang.Object>
OBJECT_CONSTRUCTOR
static boolean
POJO_SCHEMA_ON_COLLECTION_FIELDS
Disabled by default.static boolean
POJO_SCHEMA_ON_MAP_FIELDS
Disabled by default.static boolean
PRESERVE_NULL_ELEMENTS
Disabled by default.static boolean
USE_SUN_MISC_UNSAFE
If true, sun.misc.Unsafe is used to access the fields of the objects instead of plain java reflections.
-
Constructor Summary
Constructors Modifier Constructor Description private
RuntimeEnv()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <T> java.lang.reflect.Constructor<T>
getConstructor(java.lang.Class<T> clazz)
private static java.lang.reflect.Method
getMethodNewInstanceFromObjectInputStream()
(package private) static <T> java.lang.Class<T>
loadClass(java.lang.String className)
static <T> RuntimeEnv.Instantiator<T>
newInstantiator(java.lang.Class<T> clazz)
Returns an instatiator for the specifiedclazz
.
-
-
-
Field Detail
-
JAVA_9_AND_ABOVE
public static final boolean JAVA_9_AND_ABOVE
true
for JDKs 9, 10, 11, etc;false
for 1.8 and below.
-
ENUMS_BY_NAME
public static final boolean ENUMS_BY_NAME
Returns true if serializing enums by name is activated. Disabled by default.
-
AUTO_LOAD_POLYMORPHIC_CLASSES
public static final boolean AUTO_LOAD_POLYMORPHIC_CLASSES
Enabled by default. For security purposes, you probably would want to register all known classes and disable this option.
-
PRESERVE_NULL_ELEMENTS
public static final boolean PRESERVE_NULL_ELEMENTS
Disabled by default. Writes a sentinel value (uint32) in place of null values in collections/arrays. Works only on the binary formats (protostuff/graph/protobuf).
-
MORPH_NON_FINAL_POJOS
public static final boolean MORPH_NON_FINAL_POJOS
Disabled by default. For pojos that are not declared final, they could still be morphed to their respective subclasses (inheritance). Enable this option if your parent classes aren't abstract classes.
-
MORPH_COLLECTION_INTERFACES
public static final boolean MORPH_COLLECTION_INTERFACES
Disabled by default. If true, type metadata will be included on serialization for fields that are collection interfaces. Enabling this is useful if you want to retain the actual collection impl used.If disabled, type metadata will not be included and instead, will be mapped to a default impl.
Collection = ArrayList List = ArrayList Set = HashSet SortedSet = TreeSet NavigableSet = TreeSet Queue = LinkedList BlockingQueue = LinkedBlockingQueue Deque = LinkedList BlockingDequeue = LinkedBlockingDeque
You can optionally enable only for a particular field by annotating it with
Morph
.
-
MORPH_MAP_INTERFACES
public static final boolean MORPH_MAP_INTERFACES
Disabled by default. If true, type metadata will be included on serialization for fields that are map interfaces. Enabling this is useful if you want to retain the actual map impl used.If disabled, type metadata will not be included and instead, will be mapped to a default impl.
Map = HashMap SortedMap = TreeMap NavigableMap = TreeMap ConcurrentMap = ConcurrentHashMap ConcurrentNavigableMap = ConcurrentSkipListMap
You can optionally enable only for a particular field by annotating it with
Morph
.
-
COLLECTION_SCHEMA_ON_REPEATED_FIELDS
public static final boolean COLLECTION_SCHEMA_ON_REPEATED_FIELDS
On repeated fields, the List/Collection itself is not serialized (only its values). If you enable this option, the repeated field will be serialized as a standalone message with a collection schema. Even if the List/Collection is empty, an empty collection message is still written.This is particularly useful if you rely on
Object.equals(Object)
on your pojos.Disabled by default for protobuf compatibility.
-
POJO_SCHEMA_ON_COLLECTION_FIELDS
public static final boolean POJO_SCHEMA_ON_COLLECTION_FIELDS
Disabled by default. If enabled, a list's internal state/fields will be serialized instead of just its elements.
-
POJO_SCHEMA_ON_MAP_FIELDS
public static final boolean POJO_SCHEMA_ON_MAP_FIELDS
Disabled by default. If enabled, a map's internal state/fields will be serialized instead of just its elements.
-
USE_SUN_MISC_UNSAFE
public static final boolean USE_SUN_MISC_UNSAFE
If true, sun.misc.Unsafe is used to access the fields of the objects instead of plain java reflections. Enabled by default if running on a sun jre.
-
ALWAYS_USE_SUN_REFLECTION_FACTORY
public static final boolean ALWAYS_USE_SUN_REFLECTION_FACTORY
If true, the constructor will always be obtained fromReflectionFactory.newConstructorFromSerialization
.Disabled by default, which means that if the pojo has a no-args constructor, that will be used instead.
Enable this if you intend to avoid deserializing objects whose no-args constructor initializes (unwanted) internal state. This applies to complex/framework objects.
If you intend to fill default field values using your default constructor, leave this disabled. This normally applies to java beans/data objects.
-
NEVER_USE_SUN_REFLECTION_FACTORY
public static final boolean NEVER_USE_SUN_REFLECTION_FACTORY
If true, the constructor will never be obtained fromReflectionFactory.newConstructorFromSerialization
.Disabled by default, which means that if the pojo has no default constructor, sun reflection will be instead.
Enable this if you intend to enforce filling default field values using your default constructor. This applies to complex/framework objects which may be designed with non-default constructors only. Usually it only makes sense to use this option in your development environment to fail fast on those objects instead of deferring a problem of non-initialized fields to later stages.
-
newInstanceFromObjectInputStream
static final java.lang.reflect.Method newInstanceFromObjectInputStream
-
OBJECT_CONSTRUCTOR
static final java.lang.reflect.Constructor<java.lang.Object> OBJECT_CONSTRUCTOR
-
ID_STRATEGY
public static final IdStrategy ID_STRATEGY
-
-
Method Detail
-
getMethodNewInstanceFromObjectInputStream
private static java.lang.reflect.Method getMethodNewInstanceFromObjectInputStream()
-
loadClass
static <T> java.lang.Class<T> loadClass(java.lang.String className)
-
newInstantiator
public static <T> RuntimeEnv.Instantiator<T> newInstantiator(java.lang.Class<T> clazz)
Returns an instatiator for the specifiedclazz
.
-
getConstructor
private static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz)
-
-