de.agilecoders.wicket.jquery.util
Class Json

java.lang.Object
  extended by de.agilecoders.wicket.jquery.util.Json

public final class Json
extends Object

Helper functions to handle JsonNode values.

Author:
miha

Nested Class Summary
static class Json.ParseException
          Json parser runtime exception.
static class Json.RawValue
          An object that can be used to render raw String value, i.e.
 
Method Summary
static
<T> T
fromJson(com.fasterxml.jackson.databind.JsonNode json, Class<T> clazz)
          Convert a JsonNode to a Java value
static
<T> T
fromJson(String json, Class<T> clazz)
          Convert a JsonNode to a Java value
static
<T> T
fromJson(String json, com.fasterxml.jackson.databind.JavaType type)
          Convert a string to a Java value
static boolean isValid(String json)
          verifies a valid json string
static com.fasterxml.jackson.databind.node.ObjectNode newObject()
          Creates a new empty ObjectNode.
static com.fasterxml.jackson.databind.JsonNode parse(String jsonString)
          Parse a String representing a json, and return it as a JsonNode.
static String stringify(com.fasterxml.jackson.databind.JsonNode json)
          Convert a JsonNode to its string representation.
static String stringify(Object data)
          Convert an object to a json string representation.
static com.fasterxml.jackson.databind.JsonNode toJson(Object data)
          Convert an object to JsonNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fromJson

public static <T> T fromJson(String json,
                             com.fasterxml.jackson.databind.JavaType type)
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

public static com.fasterxml.jackson.databind.JsonNode toJson(Object data)
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

public static <T> T fromJson(com.fasterxml.jackson.databind.JsonNode json,
                             Class<T> clazz)
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

public static <T> T fromJson(String json,
                             Class<T> clazz)
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

public static String stringify(com.fasterxml.jackson.databind.JsonNode json)
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

public static String stringify(Object data)
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

public static boolean isValid(String json)
verifies a valid json string

Parameters:
json - The json string
Returns:
true, if string is a valid json string

parse

public static com.fasterxml.jackson.databind.JsonNode parse(String jsonString)
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


Copyright © 2017. All Rights Reserved.