- Type Parameters:
T
- target type, may be unchecked
- All Known Subinterfaces:
Jose.Extension<T>
public interface IuJsonAdapter<T>
Adapts JSON values to equivalent Java types.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> IuJsonAdapter
<T> basic()
Provides a basic JSON type adapter.static <T> IuJsonAdapter
<T> from
(Class<T> type, IuJsonPropertyNameFormat propertyNameFormat, Function<Type, IuJsonAdapter<?>> valueAdapter) Creates a JSON type adapter that converts from a JavaBeans business object type to and from JSON.static <T> IuJsonAdapter
<T> Creates a functional JSON type adapter.static <T> IuJsonAdapter
<T> Creates a functional JSON type adapter.Converts a JSON parameter value to its Java equivalent.static <T> IuJsonAdapter
<T> of
(Class<? super T> type, IuJsonAdapter<?> valueAdapter) Provides a JSON type adapter that delegates to another adapter for parameterized values.static <T> IuJsonAdapter
<T> Provides a standard JSON type adapter for a Java value.static <T> IuJsonAdapter
<T> Provides a JSON type adapter for the erasure of a generic type.static <T> IuJsonAdapter
<T> of
(Type type, Function<Class<?>, IuJsonAdapter<?>> valueAdapter) Provides a JSON type adapter that delegates to another adapter for parameterized values.static <T> IuJsonAdapter
<T> Creates a functional JSON type adapter for text conversion.static <T> IuJsonAdapter
<T> Creates a functional JSON type adapter.static <T> IuJsonAdapter
<T> Creates a functional JSON type adapter.Converts a value to its JSON equivalent.
-
Method Details
-
from
Creates a functional JSON type adapter.- Type Parameters:
T
- target type- Parameters:
fromJson
- function that converts from JSON to the target type- Returns:
- functional adapter
-
text
Creates a functional JSON type adapter for text conversion.- Type Parameters:
T
- target type- Parameters:
parser
- parsing function- Returns:
- functional adapter
-
text
Creates a functional JSON type adapter.- Type Parameters:
T
- target type- Parameters:
parser
- parsing functionprint
- printing function- Returns:
- functional adapter
-
to
Creates a functional JSON type adapter.- Type Parameters:
T
- target type- Parameters:
toJson
- function that converts from the target type to JSON- Returns:
- functional adapter
-
from
Creates a functional JSON type adapter.- Type Parameters:
T
- target type- Parameters:
fromJson
- function that converts from JSON to the target typetoJson
- function that converts from the target type to JSON- Returns:
- functional adapter
-
from
static <T> IuJsonAdapter<T> from(Class<T> type, IuJsonPropertyNameFormat propertyNameFormat, Function<Type, IuJsonAdapter<?>> valueAdapter) Creates a JSON type adapter that converts from a JavaBeans business object type to and from JSON.- Type Parameters:
T
- business object type- Parameters:
type
- business object class; must be an interface to convert from JSON, an interface is not required to convert from JSON.propertyNameFormat
- property name format to use for converting to JSONvalueAdapter
- value adapter function- Returns:
IuJsonAdapter
-
basic
Provides a basic JSON type adapter.Returns an adapter that:
- Handles undefined (null) JSON values as null
- Returns
JsonValue
as-is - Builds
JsonObjectBuilder
andJsonArrayBuilder
if provided totoJson(Object)
as Java values - Converts between null and
JsonValue.NULL
- Converts between
Boolean
andJsonValue.TRUE
/JsonValue.FALSE
- Converts between
String
andJsonString
- Converts between
Number
andJsonNumber
,fromJson(JsonValue)
returnsBigDecimal
- Converts between
List<?>
andJsonArray
, with recursive item conversion - Converts between
Map<String, ?>
andJsonObject
, with recursive conversion - Converts irreversibly to
JsonValue
for other types listed inof(Class)
.
Equivalent to
of(Object.class)
- Type Parameters:
T
- target type, may be used for unchecked cast to a one of the types listed above. For full generic type support and two-way conversion useof(Class)
- Returns:
IuJsonAdapter
- Throws:
ClassCastException
- (potentially upstream) If the target type doesn't match the return type
-
of
Provides a JSON type adapter for the erasure of a generic type.The adapter returned is aware of
ParameterizedType
andGenericArrayType
arguments indicating item, component, and value types. All types referenced by generic type arguments must be included in the list below.Supports:
Boolean
andboolean
Object
, seebasic()
for Object conversion rulesVoid
andvoid
, supporting only null valuestoJson(Object)
asJsonNumber
toJson(Object)
returnsJsonString
- byte[], via
IuText.base64(String)
andIuText.base64(byte[])
BigInteger
CharSequence
Calendar
, asDate
CharSequence
, asString
Date
, asTemporal
Duration
Enum
subtypesInstant
LocalDate
LocalTime
LocalDateTime
OffsetDateTime
OffsetTime
Optional
Period
SimpleTimeZone
String
Pattern
TimeZone
URI
URL
ZonedDateTime
ZoneId
ZoneOffset
- byte[], via
toJson(Object)
asJsonArray
Array
typeArrayList
Collection
, asQueue
Deque
, asArrayDeque
Enumeration
HashSet
Iterable
, asCollection
Iterator
LinkedHashSet
List
, asArrayList
NavigableSet
, asTreeSet
Queue
, asDeque
Set
, asLinkedHashSet
SortedSet
, asNavigableSet
Properties
, enforces values asString
TreeSet
Stream
toJson(Object)
asJsonObject
:
- Type Parameters:
T
- target type- Parameters:
type
- target type- Returns:
IuJsonAdapter
-
of
Provides a standard JSON type adapter for a Java value.- Type Parameters:
T
- target type- Parameters:
type
- target type- Returns:
IuJsonAdapter
- See Also:
-
of
Provides a JSON type adapter that delegates to another adapter for parameterized values.- Type Parameters:
T
- target type- Parameters:
type
- target typevalueAdapter
- Value type adapter forJsonStructure
conversion, may be null if the Java type doesn't declare parameters, or to use a standard value adapter- Returns:
IuJsonAdapter
- See Also:
-
of
Provides a JSON type adapter that delegates to another adapter for parameterized values.- Type Parameters:
T
- target type- Parameters:
type
- target typevalueAdapter
- Factory function for supplying a value type adapter forJsonStructure
conversion based on the item type.- Returns:
IuJsonAdapter
- See Also:
-
fromJson
Converts a JSON parameter value to its Java equivalent.- Parameters:
jsonValue
- JSON value- Returns:
- Java equivalent
-
toJson
Converts a value to its JSON equivalent.- Parameters:
value
- value- Returns:
- JSON equivalent
-