Package org.djutils.data.serialization
Class StringSerializer
java.lang.Object
org.djutils.data.serialization.StringSerializer
- All Implemented Interfaces:
SpecificTextSerializer<String>
,TextSerializer<String>
StringSerializer (de)serializes String objects.
Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(Class<String> type, String text, String unit) Deserialize a value from text that has been created with the corresponding serializer.Serialize a value to text in such a way that it can be deserialized with the corresponding deserializer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.djutils.data.serialization.SpecificTextSerializer
deserialize, serialize
-
Constructor Details
-
StringSerializer
public StringSerializer()
-
-
Method Details
-
serialize
Description copied from interface:TextSerializer
Serialize a value to text in such a way that it can be deserialized with the corresponding deserializer. Note thatnull
values for value are allowed. Anull
values stands for an empty column value in a CVS-file, a missing tag in an XML-file, etc.- Specified by:
serialize
in interfaceTextSerializer<String>
- Parameters:
value
- T; the value to serialize, may benull
unit
- String; the unit used to convert the data to and store, so all valus in a column may have the same unit. The value may benull
or blank- Returns:
- String; a string representation of the value that can later be deserialized, or
null
to denote a missing value
-
deserialize
Description copied from interface:TextSerializer
Deserialize a value from text that has been created with the corresponding serializer. Note thatnull
values for text are allowed. Anull
values stands for an empty column value in a CVS-file, a missing tag in an XML-file, etc. In this way, we can explicitly show values that were not specified in the file. Also, the type may benull
; this is, for instance, the case for anyTextSerializer
implementingSpecificTextSerializer
, where no class needs to be provided (although it can).- Specified by:
deserialize
in interfaceTextSerializer<String>
- Parameters:
type
- Class<T>; class of the value type, may benull
text
- String; the string to deserialize, may benull
or blankunit
- String; unit with the value, may benull
or blank- Returns:
- T; an instance of the object created with the corresponding serializer, may be
null
when a value was not specified in the source from which the deserializer was called
-