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