java.lang.Object
de.agilecoders.wicket.jquery.util.Json
Helper functions to handle JsonNode values.
- Author:
- miha
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classJson parser runtime exception.static final classAn object that can be used to render raw String value, i.e. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConvert a JsonNode to a Java valuestatic <T> TConvert a string to a Java valuestatic <T> TConvert a JsonNode to a Java valuestatic booleanverifies a valid json stringstatic com.fasterxml.jackson.databind.node.ObjectNodeCreates a new empty ObjectNode.static com.fasterxml.jackson.databind.JsonNodeParse a String representing a json, and return it as a JsonNode.static Stringstringify(com.fasterxml.jackson.databind.JsonNode json) Convert a JsonNode to its string representation.static StringConvert an object to a json string representation.static com.fasterxml.jackson.databind.JsonNodeConvert an object to JsonNode.
-
Method Details
-
fromJson
Convert a string to a Java value- Type Parameters:
T- type of return object- Parameters:
json- Json value to convert.type- Expected Java value type.- Returns:
- casted value of given json object
- Throws:
Json.ParseException- to runtime if json node can't be casted to clazz.
-
toJson
Convert an object to JsonNode.- Parameters:
data- Value to convert in Json.- Returns:
- creates a new json object from given data object
- Throws:
Json.ParseException- to runtime if object can't be parsed
-
fromJson
Convert a JsonNode to a Java value- Type Parameters:
T- type of return object- Parameters:
json- Json value to convert.clazz- Expected Java value type.- Returns:
- casted value of given json object
- Throws:
Json.ParseException- to runtime if json node can't be casted to clazz.
-
fromJson
Convert a JsonNode to a Java value- Type Parameters:
T- type of return object- Parameters:
json- Json value to convert.clazz- Expected Java value type.- Returns:
- casted value of given json object
-
newObject
public static com.fasterxml.jackson.databind.node.ObjectNode newObject()Creates a new empty ObjectNode.- Returns:
- a new empty json object.
-
stringify
Convert a JsonNode to its string representation. If given value is null an empty json object will returned.- Parameters:
json- The json object to toJsonString- Returns:
- stringified version of given json object
-
stringify
Convert an object to a json string representation. If given value is null an empty json object will returned.- Parameters:
data- The data object to toJsonString- Returns:
- stringified version of given json object
-
isValid
verifies a valid json string- Parameters:
json- The json string- Returns:
- true, if string is a valid json string
-
parse
Parse a String representing a json, and return it as a JsonNode.- Parameters:
jsonString- string to parse- Returns:
- parsed json string as json node
- Throws:
Json.ParseException- to runtime if json string can't be parsed
-