Interface RecordPart


public interface RecordPart
Represents the top-level component of a 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.
Since:
5.5
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the raw JSON string that this object wraps.
    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.
  • Method Details

    • toObject

      @Nonnull <T> T toObject(@Nonnull 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 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.
      Returns:
      object of type T, obtained as the result of the mapping
      Throws:
      ParsingException - if the mapping fails to produce a result
    • toMap

      @Nonnull Map<String,Object> toMap() throws ParsingException
      Presents a parsed form of the underlying JSON message as a 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.

      Returns:
      Map representation of the JSON data
      Throws:
      ParsingException - if the underlying JSON message fails to parse
    • toJson

      @Nonnull 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).