public class JsonConfigHelper
extends java.lang.Object
| Constructor and Description |
|---|
JsonConfigHelper()
Creates an empty JSON configuration
|
JsonConfigHelper(java.io.File jsonFile)
Creates a JSON configuration from the specified file
|
JsonConfigHelper(java.io.InputStream jsonIn)
Creates a JSON configuration from the specified input stream
|
JsonConfigHelper(java.util.Map<java.lang.String,java.lang.Object> rootNode)
Creates a JSON configuration from a map.
|
JsonConfigHelper(java.io.Reader jsonReader)
Creates a JSON configuration from the specified reader
|
JsonConfigHelper(java.lang.String jsonContent)
Creates a JSON configuration from the specified string
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
get(java.lang.String path)
Gets the value of the specified node
|
java.lang.String |
get(java.lang.String path,
java.lang.String defaultValue)
Gets the value of the specified node, with a specified default if the not
was not found
|
java.util.List<JsonConfigHelper> |
getJsonList(java.lang.String path)
Get list of JsonConfigHelper of the specified node
|
java.util.Map<java.lang.String,JsonConfigHelper> |
getJsonMap(java.lang.String path)
Get the JSON Map of the specified node
|
java.util.List<java.lang.Object> |
getList(java.lang.String path)
Gets values of the specified node as a list.
|
java.util.Map<java.lang.String,java.lang.Object> |
getMap(java.lang.String path)
Gets a map of the child nodes of the specified node
|
java.util.Map<java.lang.String,java.lang.Object> |
getMapWithChild(java.lang.String path)
Gets a map of the child (and the 2nd level children) nodes of the
specified node
|
java.lang.String |
getPlainText(java.lang.String path,
java.lang.String defaultValue)
Get the value of specified node, with a specified default if it's not
found
|
void |
move(java.lang.String source,
java.lang.String dest)
Move node from one path to another path in the JSON
|
void |
moveAfter(java.lang.String path,
java.lang.String refPath)
Move node to a node after the specified node
|
void |
moveBefore(java.lang.String path,
java.lang.String refPath)
Move node to a node before the specified node
|
void |
removePath(java.lang.String path)
Remove specified path from json
|
void |
set(java.lang.String path,
java.lang.String value)
Sets the value of the specified node.
|
void |
setJsonList(java.lang.String path,
java.util.List<JsonConfigHelper> jsonList)
Set Map on the specified path
|
void |
setJsonMap(java.lang.String path,
java.util.Map<java.lang.String,JsonConfigHelper> map)
Set Map on the specified path
|
void |
setMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> map)
Set map with its child
|
void |
setMultiMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> json)
Set Multiple nested map on the specified path
|
void |
store(java.io.Writer writer)
Serialises the current state of the JSON configuration to the specified
writer.
|
void |
store(java.io.Writer writer,
boolean pretty)
Serialises the current state of the JSON configuration to the specified
writer.
|
java.lang.String |
toString()
Convert Json to String
|
java.lang.String |
toString(boolean pretty)
Convert Json to String
|
public JsonConfigHelper()
public JsonConfigHelper(java.util.Map<java.lang.String,java.lang.Object> rootNode)
rootNode - a JSON structured mappublic JsonConfigHelper(java.lang.String jsonContent)
throws java.io.IOException
jsonContent - a JSON content stringjava.io.IOException - if there was an error parsing or reading the contentpublic JsonConfigHelper(java.io.File jsonFile)
throws java.io.IOException
jsonFile - a JSON filejava.io.IOException - if there was an error parsing or reading the filepublic JsonConfigHelper(java.io.InputStream jsonIn)
throws java.io.IOException
jsonIn - a JSON streamjava.io.IOException - if there was an error parsing or reading the streampublic JsonConfigHelper(java.io.Reader jsonReader)
throws java.io.IOException
jsonReader - a reader for a JSON filejava.io.IOException - if there was an error parsing or reading the readerpublic java.lang.String get(java.lang.String path)
path - XPath to nodepublic java.lang.String get(java.lang.String path,
java.lang.String defaultValue)
path - XPath to nodedefaultValue - value to return if the node was not foundpublic java.lang.String getPlainText(java.lang.String path,
java.lang.String defaultValue)
path - defaultValue - public java.util.List<java.lang.Object> getList(java.lang.String path)
path - XPath to nodepublic java.util.Map<java.lang.String,java.lang.Object> getMap(java.lang.String path)
path - XPath to nodepublic java.util.List<JsonConfigHelper> getJsonList(java.lang.String path)
path - XPath to nodepublic java.util.Map<java.lang.String,JsonConfigHelper> getJsonMap(java.lang.String path)
path - XPath to nodepublic void setMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> map)
path - XPath to nodemap - node Mappublic void setMultiMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> json)
path - XPath to nodejson - node Mappublic void setJsonMap(java.lang.String path,
java.util.Map<java.lang.String,JsonConfigHelper> map)
path - XPath to nodemap - node Mappublic void setJsonList(java.lang.String path,
java.util.List<JsonConfigHelper> jsonList)
path - XPath to nodemap - node Mappublic java.util.Map<java.lang.String,java.lang.Object> getMapWithChild(java.lang.String path)
path - XPath to nodepublic void removePath(java.lang.String path)
path - to nodepublic void set(java.lang.String path,
java.lang.String value)
path - XPath to nodevalue - value to setpublic void move(java.lang.String source,
java.lang.String dest)
source - XPath to nodedest - XPath to nodepublic void moveBefore(java.lang.String path,
java.lang.String refPath)
path - XPath to noderefPath - XPath to nodepublic void moveAfter(java.lang.String path,
java.lang.String refPath)
path - XPath to noderefPath - XPath to nodepublic void store(java.io.Writer writer)
throws java.io.IOException
writer - a writerjava.io.IOException - if there was an error writing the configurationpublic void store(java.io.Writer writer,
boolean pretty)
throws java.io.IOException
writer - a writerpretty - use pretty printerjava.io.IOException - if there was an error writing the configurationpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(boolean pretty)
pretty - state to format the layout of the Json configuration fileCopyright © 2009-2019. All Rights Reserved.