java.lang.Object
imagingbook.common.util.ObjectUtils
Defines static methods for object copying and encoding to strings.
- Version:
- 2022/09/11
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
copy
(T entity) Returns a shallow copy of the given object using reflection.static Object
decodeFromString
(String string) Decodes and deserializes an object encoded withencodeToString(Object)
.static String
encodeToString
(Object object) Serializes and encodes an arbitrary object to a string.
-
Method Details
-
copy
Returns a shallow copy of the given object using reflection. This can be used if theCloneable
interface is not (or cannot be) implemented.- Type Parameters:
T
- generic type- Parameters:
entity
- the object to be copied- Returns:
- the object copy
-
encodeToString
Serializes and encodes an arbitrary object to a string. This is potentially dangerous and only intended for local use, e.g., to define constant matrices with full precision. The string encoding is 'Base64' implemented with standard Java8 functionality. SeedecodeFromString(String)
for decoding.- Parameters:
object
- an arbitrary object- Returns:
- the Base64 string encoding of the object
-
decodeFromString
Decodes and deserializes an object encoded withencodeToString(Object)
. The type of the encoded object must be known.- Parameters:
string
- the encoded object string- Returns:
- the associated object (cast to the known type)
-