Package com.hazelcast.jet.cdc
Interface RecordPart
-
@EvolvingApi public interface RecordPart
Represents the top-level component of aChangeRecord
, 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.- Since:
- Jet 4.2
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
toJson()
Returns the raw JSON string that this object wraps.java.util.Map<java.lang.String,java.lang.Object>
toMap()
Presents a parsed form of the underlying JSON message as aMap
.<T> T
toObject(java.lang.Class<T> clazz)
Maps the entire element to an instance of the specified class.
-
-
-
Method Detail
-
toObject
@Nonnull <T> T toObject(@Nonnull java.lang.Class<T> clazz) throws ParsingException
Maps the entire element to an instance of the specified class.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 typeDATE
and we want to map it to a field namedbirthDate
in our row object, of typeLocalDate
. We would write code like this:public LocalDate birthDate; public void setBirthDate(long dateInEpochDays) { this.birthDate = dateInEpochDays == 0 ? null : LocalDate.ofEpochDay(dateInEpochDays); }
long
we force the object mapping to interpret the column value as along
(as opposed toDate
). Then we can take care ofnull
handling and converting to whatever desired type ourselves.- Returns:
- object of type
T
, obtained as the result of the mapping - Throws:
ParsingException
- if the mapping fails to produce a result
-
toMap
@Nonnull java.util.Map<java.lang.String,java.lang.Object> toMap() throws ParsingException
Presents a parsed form of the underlying JSON message as aMap
. 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.
- Returns:
Map
representation of the JSON data- Throws:
ParsingException
- if the underlying JSON message fails to parse
-
toJson
@Nonnull java.lang.String toJson()
Returns the raw JSON string that this object wraps. You can use it if parsing is failing for some reason (for example on some untested DB-connector version combination).
-
-