Class JacksonFormat

java.lang.Object
com.github.siroshun09.configapi.format.jackson.JacksonFormat
All Implemented Interfaces:
FileFormat<MapNode>

public final class JacksonFormat extends Object implements FileFormat<MapNode>
A FileFormat implementation that loading/saving MapNode from/to json files using Jackson's ObjectMapper.

Supported Nodes:

  • Field Details

    • DEFAULT

      public static final JacksonFormat DEFAULT
      An instance of JacksonFormat that created from a plain ObjectMapper.
    • PRETTY_PRINTING

      public static final JacksonFormat PRETTY_PRINTING
      An instance of JacksonFormat that created from a ObjectMapper that is enabled pretty printing.
  • Constructor Details

    • JacksonFormat

      public JacksonFormat(@NotNull @NotNull com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      The constructor of JacksonFormat.
      Parameters:
      objectMapper - an ObjectMapper that is used for serializing/deserializing json
  • Method Details

    • createDefaultPrettyPrinter

      @Contract(" -> new") @NotNull public static @NotNull com.fasterxml.jackson.core.util.DefaultPrettyPrinter createDefaultPrettyPrinter()
      Creates a DefaultPrettyPrinter that prints json like Gson.
      Returns:
      a DefaultPrettyPrinter
    • load

      @NotNull public @NotNull MapNode load(@NotNull @NotNull Path filepath) throws IOException
      Description copied from interface: FileFormat
      Loads a node from a file.
      Specified by:
      load in interface FileFormat<MapNode>
      Parameters:
      filepath - a filepath to load a node
      Returns:
      a loaded Node (FileFormat)
      Throws:
      IOException - if I/O error occurred
    • load

      @NotNull public @NotNull MapNode load(@NotNull @NotNull Reader reader) throws IOException
      Description copied from interface: FileFormat
      Loads a node from a Reader.
      Specified by:
      load in interface FileFormat<MapNode>
      Parameters:
      reader - a Reader to load a node
      Returns:
      a loaded Node (FileFormat)
      Throws:
      IOException - if I/O error occurred
    • save

      public void save(@NotNull @NotNull MapNode node, @NotNull @NotNull Writer writer) throws IOException
      Description copied from interface: FileFormat
      Saves a node to a Writer.
      Specified by:
      save in interface FileFormat<MapNode>
      Parameters:
      node - a root Node (FileFormat) to save
      writer - a Writer to write a node
      Throws:
      IOException - if I/O error occurred