Package org.openbravo.service.json
Class JsonUtils
- java.lang.Object
-
- org.openbravo.service.json.JsonUtils
-
public class JsonUtils extends Object
Contains utility methods used in this module.- Author:
- mtaal
-
-
Constructor Summary
Constructors Constructor Description JsonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.codehaus.jettison.json.JSONObject
buildCriteria(Map<String,String> parameters)
static String
convertExceptionToJson(Throwable throwable)
Converts an exception to its json represention.static String
convertFromXSDToJavaFormat(String dateValue)
Removes the colon in the timezone definition, seeconvertToCorrectXSDFormat(String)
.static String
convertToCorrectXSDFormat(String dateValue)
Adds a colon in the timezone part of the formatted date, see here: http://weblogs.java.net/blog/felipegaucho/archive/2009/12/06/jaxb-customization-xsddatetimestatic SimpleDateFormat
createDateFormat()
static SimpleDateFormat
createDateTimeFormat()
Note the formatted date string must be repaired in the timezone to follow the XSD format, see:convertToCorrectXSDFormat(String)
.static SimpleDateFormat
createJSTimeFormat()
static SimpleDateFormat
createTimeFormat()
static SimpleDateFormat
createTimeFormatWithoutGMTOffset()
static List<String>
getAdditionalProperties(Map<String,String> parameters)
Gets the value of theJsonConstants.ADDITIONAL_PROPERTIES_PARAMETER
in the parameters map and returns it as a list of String, if no parameter is set an empty list is returned.static String
getEmptyResult()
Returns an empty result for a fetch callstatic List<Property>
getIdentifierSet(Property property)
A utility method which retrieves the properties used for identifying an entity and its first level references.static List<Property>
getPropertiesOnPath(Entity entity, String propertyPath)
Determines the list of properties based on the property path (for example bankAccount.bank.name).static boolean
isQueryTimeout(Throwable localThrowable)
static boolean
isValueEmpty(String value)
Returns whether a JSON value is empty.
-
-
-
Method Detail
-
getIdentifierSet
public static List<Property> getIdentifierSet(Property property)
A utility method which retrieves the properties used for identifying an entity and its first level references. Takes into accoun the different scenarios implemented in theIdentifierProvider.getIdentifier(Object)
method. Is used by distinct queries to get the smallest possible select clauses.
-
createDateFormat
public static SimpleDateFormat createDateFormat()
- Returns:
- a new instance of the
SimpleDateFormat
using a format of yyyy-MM-dd (xml schema date format). The date format has lenient set to true.
-
createTimeFormat
public static SimpleDateFormat createTimeFormat()
- Returns:
- a new instance of the
SimpleDateFormat
using a format of HH:MM:SS+0000. The date format has lenient set to true.
-
createTimeFormatWithoutGMTOffset
public static SimpleDateFormat createTimeFormatWithoutGMTOffset()
- Returns:
- a new instance of the
SimpleDateFormat
using a format of HH:MM:SS. The date format has lenient set to true.
-
createJSTimeFormat
public static SimpleDateFormat createJSTimeFormat()
- Returns:
- a new instance of the
SimpleDateFormat
using a format of yyyy-MM-dd'T'HH:mm:ss (see http://www.w3.org/TR/xmlschema-2/#dateTime). The date format has lenient set to true.
-
createDateTimeFormat
public static SimpleDateFormat createDateTimeFormat()
Note the formatted date string must be repaired in the timezone to follow the XSD format, see:convertToCorrectXSDFormat(String)
.- Returns:
- a new instance of the
SimpleDateFormat
using a format of yyyy-MM-dd'T'HH:mm:ss (xml schema date time format). The date format has lenient set to true.
-
convertToCorrectXSDFormat
public static String convertToCorrectXSDFormat(String dateValue)
Adds a colon in the timezone part of the formatted date, see here: http://weblogs.java.net/blog/felipegaucho/archive/2009/12/06/jaxb-customization-xsddatetime- Parameters:
dateValue
- the date value without a :, for example 2009-12-06T15:59:34+0100- Returns:
- a colon added in the timezone part: 2009-12-06T15:59:34+01:00
-
convertFromXSDToJavaFormat
public static String convertFromXSDToJavaFormat(String dateValue)
Removes the colon in the timezone definition, seeconvertToCorrectXSDFormat(String)
.
-
getAdditionalProperties
public static List<String> getAdditionalProperties(Map<String,String> parameters)
Gets the value of theJsonConstants.ADDITIONAL_PROPERTIES_PARAMETER
in the parameters map and returns it as a list of String, if no parameter is set an empty list is returned.- Parameters:
parameters
- the parameter map to search for theJsonConstants.ADDITIONAL_PROPERTIES_PARAMETER
parameter- Returns:
- the values in the
JsonConstants.ADDITIONAL_PROPERTIES_PARAMETER
parameter
-
convertExceptionToJson
public static String convertExceptionToJson(Throwable throwable)
Converts an exception to its json represention. Uses the Smartclient format for the json string, see here: RestDataSource- Parameters:
throwable
- the exception to convert to json- Returns:
- the resulting json string
-
isQueryTimeout
public static boolean isQueryTimeout(Throwable localThrowable)
-
getEmptyResult
public static String getEmptyResult()
Returns an empty result for a fetch call- Returns:
- the JSON representation of an empty result
-
getPropertiesOnPath
public static List<Property> getPropertiesOnPath(Entity entity, String propertyPath)
Determines the list of properties based on the property path (for example bankAccount.bank.name).- Parameters:
entity
- the entity to start from, the first property in the property path is a property of this entitypropertyPath
- the property path, i.e. property names separated by dots- Returns:
- the list of properties determined from the property path
-
buildCriteria
public static org.codehaus.jettison.json.JSONObject buildCriteria(Map<String,String> parameters)
-
isValueEmpty
public static boolean isValueEmpty(String value)
Returns whether a JSON value is empty. The following values are considered as empty:- An empty string
null
"null"
literal"undefined"
literal
-
-