Package de.xima.fc.converter.json
Enum SimpleJsonPrimitiveConverter
- java.lang.Object
-
- java.lang.Enum<SimpleJsonPrimitiveConverter>
-
- de.xima.fc.converter.json.SimpleJsonPrimitiveConverter
-
- All Implemented Interfaces:
IJsonPrimitiveConverter,Serializable,Comparable<SimpleJsonPrimitiveConverter>
public enum SimpleJsonPrimitiveConverter extends Enum<SimpleJsonPrimitiveConverter> implements IJsonPrimitiveConverter
A defaultIJsonPrimitiveConverterthat converts between JSON primitives and strings. It recognizes only the primitive types defined by the JSON spec (null, boolean, number, boolean), represented by the usual Java classes (Boolean,Number,String.null, the empty string, as well as case-insensitive matches for "n", "f", "\0", "0", "false", "off" are converted to false. All other strings are converted to true.
Numbers are converted to their Base-10 representation. Floating point numbers are stringified as integers, when possible (i.e. 3.0 becomes "3").
- Since:
- 8.2.0
-
-
Enum Constant Summary
Enum Constants Enum Constant Description INSTANCEThe singleton instance of this converter.
-
Field Summary
Fields Modifier and Type Field Description static StringTYPE_BOOLEANThe type name for a JSON boolean.static StringTYPE_DOUBLEThe type name for a JSON double.static StringTYPE_LONGThe type name for a JSON long.static StringTYPE_NULLThe type name for a JSON null.static StringTYPE_STRINGThe type name for a JSON string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectdeserializePrimitive(SerializedPrimitive primitive)Deserializes a primitive from a string, as serialized byIJsonPrimitiveConverter.serializePrimitive(Object).SerializedPrimitiveserializePrimitive(Object primitive)Serializes a primitive to a string.static SimpleJsonPrimitiveConvertervalueOf(String name)Returns the enum constant of this type with the specified name.static SimpleJsonPrimitiveConverter[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
INSTANCE
public static final SimpleJsonPrimitiveConverter INSTANCE
The singleton instance of this converter.
-
-
Field Detail
-
TYPE_BOOLEAN
public static final String TYPE_BOOLEAN
The type name for a JSON boolean.- See Also:
- Constant Field Values
-
TYPE_DOUBLE
public static final String TYPE_DOUBLE
The type name for a JSON double.- See Also:
- Constant Field Values
-
TYPE_LONG
public static final String TYPE_LONG
The type name for a JSON long.- See Also:
- Constant Field Values
-
TYPE_NULL
public static final String TYPE_NULL
The type name for a JSON null.- See Also:
- Constant Field Values
-
TYPE_STRING
public static final String TYPE_STRING
The type name for a JSON string.- See Also:
- Constant Field Values
-
-
Method Detail
-
values
public static SimpleJsonPrimitiveConverter[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (SimpleJsonPrimitiveConverter c : SimpleJsonPrimitiveConverter.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static SimpleJsonPrimitiveConverter valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
deserializePrimitive
public Object deserializePrimitive(SerializedPrimitive primitive)
Description copied from interface:IJsonPrimitiveConverterDeserializes a primitive from a string, as serialized byIJsonPrimitiveConverter.serializePrimitive(Object).- Specified by:
deserializePrimitivein interfaceIJsonPrimitiveConverter- Parameters:
primitive- The primitive to deserialize.- Returns:
- The deserialized primitive.
-
serializePrimitive
public SerializedPrimitive serializePrimitive(Object primitive)
Description copied from interface:IJsonPrimitiveConverterSerializes a primitive to a string.- Specified by:
serializePrimitivein interfaceIJsonPrimitiveConverter- Parameters:
primitive- The primitive to serialize.- Returns:
- The serialized primitive.
-
-