Package io.protostuff.runtime
Class RuntimeSchema<T>
java.lang.Object
io.protostuff.runtime.RuntimeSchema<T>
A schema that can be generated and cached at runtime for objects that have no schema. This is particularly useful for
pojos from 3rd party libraries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
final RuntimeEnv.Instantiator
<T> static final int
static final int
static final int
private final Pipe.Schema
<T> -
Constructor Summary
ConstructorsConstructorDescriptionRuntimeSchema
(Class<T> typeClass, Collection<Field<T>> fields, RuntimeEnv.Instantiator<T> instantiator) RuntimeSchema
(Class<T> typeClass, Collection<Field<T>> fields, Constructor<T> constructor) -
Method Summary
Modifier and TypeMethodDescriptioncreateFieldMap
(Collection<Field<T>> fields) static <T> RuntimeSchema
<T> createFrom
(Class<T> typeClass) Generates a schema from the given class.static <T> RuntimeSchema
<T> createFrom
(Class<T> typeClass, IdStrategy strategy) Generates a schema from the given class.static <T> RuntimeSchema
<T> createFrom
(Class<T> typeClass, String[] exclusions, IdStrategy strategy) Generates a schema from the given class with the exclusion of certain fields.static <T> RuntimeSchema
<T> createFrom
(Class<T> typeClass, Map<String, String> declaredFields, IdStrategy strategy) Generates a schema from the given class with the declared fields (inclusive) based from the given Map.static <T> RuntimeSchema
<T> createFrom
(Class<T> typeClass, Set<String> exclusions, IdStrategy strategy) Generates a schema from the given class with the exclusion of certain fields.(package private) static void
findInstanceFields
(Class<?> typeClass) getFieldByName
(String fieldName) getFieldByNumber
(int n) int
getFieldName
(int number) Gets the field name associated with the number.int
getFieldNumber
(String name) Gets the field number associated with the name.Returns the pipe schema linked to this.static <T> Schema
<T> Gets the schema that was either registered or lazily initialized at runtime.static <T> Schema
<T> getSchema
(Class<T> typeClass, IdStrategy strategy) Gets the schema that was either registered or lazily initialized at runtime.(package private) static <T> HasSchema
<T> getSchemaWrapper
(Class<T> typeClass) Returns the schema wrapper.(package private) static <T> HasSchema
<T> getSchemaWrapper
(Class<T> typeClass, IdStrategy strategy) Returns the schema wrapper.boolean
isInitialized
(T message) Always returns true, everything is optional.static boolean
isRegistered
(Class<?> typeClass) Returns true if thetypeClass
was not lazily created.static boolean
isRegistered
(Class<?> typeClass, IdStrategy strategy) Returns true if thetypeClass
was not lazily created.static <T> boolean
Maps thebaseClass
to a specific non-interface/non-abstracttypeClass
and registers it (this must be done on application startup).final void
Deserializes a message/object from theinput
.Returns the full name of the message tied to this schema.Returns the simple name of the message tied to this schema.Creates the message/object tied to this schema.private boolean
preferHashFieldMap
(Collection<Field<T>> fields, int lastFieldNumber) static <T> boolean
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).static <T> boolean
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).(package private) static <T> Pipe.Schema
<T> resolvePipeSchema
(Schema<T> schema, Class<? super T> clazz, boolean throwIfNone) Invoked only when applications are having pipe io operations.Gets the class of the message.final void
Serializes a message/object to theoutput
.
-
Field Details
-
MIN_TAG_VALUE
public static final int MIN_TAG_VALUE- See Also:
-
MAX_TAG_VALUE
public static final int MAX_TAG_VALUE- See Also:
-
ERROR_TAG_VALUE
- See Also:
-
NO_EXCLUSIONS
-
MIN_TAG_FOR_HASH_FIELD_MAP
public static final int MIN_TAG_FOR_HASH_FIELD_MAP- See Also:
-
pipeSchema
-
fieldMap
-
typeClass
-
instantiator
-
-
Constructor Details
-
RuntimeSchema
-
RuntimeSchema
public RuntimeSchema(Class<T> typeClass, Collection<Field<T>> fields, RuntimeEnv.Instantiator<T> instantiator)
-
-
Method Details
-
map
Maps thebaseClass
to a specific non-interface/non-abstracttypeClass
and registers it (this must be done on application startup).With this approach, there is no overhead of writing the type metadata if a
baseClass
field is serialized.Returns true if the baseClass does not exist.
NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
.- Throws:
IllegalArgumentException
- if thetypeClass
is an interface or an abstract class.
-
register
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
. -
register
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
. -
isRegistered
Returns true if thetypeClass
was not lazily created.Method overload for backwards compatibility.
-
isRegistered
Returns true if thetypeClass
was not lazily created. -
getSchema
Gets the schema that was either registered or lazily initialized at runtime.Method overload for backwards compatibility.
-
getSchema
Gets the schema that was either registered or lazily initialized at runtime. -
getSchemaWrapper
Returns the schema wrapper.Method overload for backwards compatibility.
-
getSchemaWrapper
Returns the schema wrapper. -
createFrom
Generates a schema from the given class.Method overload for backwards compatibility.
-
createFrom
Generates a schema from the given class. -
createFrom
public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, String[] exclusions, IdStrategy strategy) Generates a schema from the given class with the exclusion of certain fields. -
createFrom
public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, Set<String> exclusions, IdStrategy strategy) Generates a schema from the given class with the exclusion of certain fields. -
createFrom
public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, Map<String, String> declaredFields, IdStrategy strategy) Generates a schema from the given class with the declared fields (inclusive) based from the given Map. The value of a the Map's entry will be the name used for the field (which enables aliasing). -
findInstanceFields
-
fill
-
createFieldMap
-
preferHashFieldMap
-
getPipeSchema
Returns the pipe schema linked to this. -
getFieldByNumber
- Specified by:
getFieldByNumber
in interfaceFieldMap<T>
-
getFieldByName
- Specified by:
getFieldByName
in interfaceFieldMap<T>
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCount
in interfaceFieldMap<T>
-
getFields
-
typeClass
Description copied from interface:Schema
Gets the class of the message. -
messageName
Description copied from interface:Schema
Returns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();- Specified by:
messageName
in interfaceSchema<T>
-
messageFullName
Description copied from interface:Schema
Returns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();- Specified by:
messageFullName
in interfaceSchema<T>
-
getFieldName
Description copied from interface:Schema
Gets the field name associated with the number. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return String.valueOf(number);
- Specified by:
getFieldName
in interfaceSchema<T>
-
getFieldNumber
Description copied from interface:Schema
Gets the field number associated with the name. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return Integer.parseInt(name);
- Specified by:
getFieldNumber
in interfaceSchema<T>
-
mergeFrom
Description copied from interface:Schema
Deserializes a message/object from theinput
.- Specified by:
mergeFrom
in interfaceSchema<T>
- Throws:
IOException
-
writeTo
Description copied from interface:Schema
Serializes a message/object to theoutput
.- Specified by:
writeTo
in interfaceSchema<T>
- Throws:
IOException
-
isInitialized
Always returns true, everything is optional.- Specified by:
isInitialized
in interfaceSchema<T>
-
newMessage
Description copied from interface:Schema
Creates the message/object tied to this schema.- Specified by:
newMessage
in interfaceSchema<T>
-
resolvePipeSchema
static <T> Pipe.Schema<T> resolvePipeSchema(Schema<T> schema, Class<? super T> clazz, boolean throwIfNone) Invoked only when applications are having pipe io operations.
-