Class JacksonFormat
java.lang.Object
com.github.siroshun09.configapi.format.jackson.JacksonFormat
- All Implemented Interfaces:
FileFormat<MapNode>
A
FileFormat
implementation that loading/saving MapNode
from/to json files using Jackson's ObjectMapper
.
Supported Node
s:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final JacksonFormat
An instance ofJacksonFormat
that created from a plainObjectMapper
.static final JacksonFormat
An instance ofJacksonFormat
that created from aObjectMapper
that is enabled pretty printing. -
Constructor Summary
ConstructorDescriptionJacksonFormat
(@NotNull com.fasterxml.jackson.databind.ObjectMapper objectMapper) The constructor ofJacksonFormat
. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.siroshun09.configapi.core.file.FileFormat
load, save, save
-
Field Details
-
DEFAULT
An instance ofJacksonFormat
that created from a plainObjectMapper
. -
PRETTY_PRINTING
An instance ofJacksonFormat
that created from aObjectMapper
that is enabled pretty printing.
-
-
Constructor Details
-
JacksonFormat
public JacksonFormat(@NotNull @NotNull com.fasterxml.jackson.databind.ObjectMapper objectMapper) The constructor ofJacksonFormat
.- Parameters:
objectMapper
- anObjectMapper
that is used for serializing/deserializing json
-
-
Method Details
-
createDefaultPrettyPrinter
@Contract(" -> new") @NotNull public static @NotNull com.fasterxml.jackson.core.util.DefaultPrettyPrinter createDefaultPrettyPrinter()Creates aDefaultPrettyPrinter
that prints json like Gson.- Returns:
- a
DefaultPrettyPrinter
-
load
Description copied from interface:FileFormat
Loads a node from a file.- Specified by:
load
in interfaceFileFormat<MapNode>
- Parameters:
filepath
- a filepath to load a node- Returns:
- a loaded
Node
(FileFormat
) - Throws:
IOException
- if I/O error occurred
-
load
Description copied from interface:FileFormat
Loads a node from aReader
.- Specified by:
load
in interfaceFileFormat<MapNode>
- Parameters:
reader
- aReader
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 aWriter
.- Specified by:
save
in interfaceFileFormat<MapNode>
- Parameters:
node
- a rootNode
(FileFormat
) to savewriter
- aWriter
to write a node- Throws:
IOException
- if I/O error occurred
-