@EvolvingApi public interface RecordPart
ChangeRecord
, such as
the key or the value. Since these components are JSON
expressions, this is actually a generic wrapper around a JSON expression.
Contains various methods for retrieving component values or for mapping
itself to data objects.Modifier and Type | Method and Description |
---|---|
String |
toJson()
Returns the raw JSON string that this object wraps.
|
Map<String,Object> |
toMap()
Presents a parsed form of the underlying JSON message as a
Map . |
<T> T |
toObject(Class<T> clazz)
Maps the entire element to an instance of the specified class.
|
@Nonnull <T> T toObject(@Nonnull Class<T> clazz) throws ParsingException
Parsing is based on Jackson jr with annotation support, so the supplied class can be annotated accordingly.
Note: there is a neat trick for converting types during object mapping.
Let's say we have a birth_date
column in a table of type
DATE
and we want to map it to a field named birthDate
in our row object, of type LocalDate
. We would write
code like this:
public LocalDate birthDate;
public void setBirthDate(long dateInEpochDays) {
this.birthDate = dateInEpochDays == 0 ? null : LocalDate.ofEpochDay(dateInEpochDays);
}
The things to note here is that by specifying a setter and giving
it the input parameter type of long
we force the object
mapping to interpret the column value as a long
(as opposed
to Date
). Then we can take care of null
handling
and converting to whatever desired type ourselves.T
, obtained as the result of the mappingParsingException
- if the mapping fails to produce a result@Nonnull Map<String,Object> toMap() throws ParsingException
Map
.
The keys are the top-level fields from the JSON and the values can range
from simple strings, numbers, collections and sub-maps.
Parsing is based on Jackson jr, you can refer to its documentation for more details.
Map
representation of the JSON dataParsingException
- if the underlying JSON message fails to
parseCopyright © 2023 Hazelcast, Inc.. All rights reserved.