com.sonyericsson.hudson.plugins.metadata.model
Class JsonUtils

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.metadata.model.JsonUtils

public abstract class JsonUtils
extends Object

Constants regarding JSON conversions.

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Nested Class Summary
static class JsonUtils.ParseException
          Exception thrown during the conversion from JSON to internal POJO representations if something went wrong.
 
Field Summary
static String CHILDREN
          The TreeNodeMetadataValue.getChildren() attribute of a node JSON object.
static String DESCRIPTION
          The Metadata.getDescription() attribute of a JSON object.
static String EXPOSED
          The AbstractMetadataValue.isExposedToEnvironment() attribute of a node JSON object.
static String GENERATED
          The MetadataValue.isGenerated() attribute of a JSON object.
static String METADATA_TYPE
          The type of the metadata object mapped via AbstractMetadataValue.AbstractMetaDataValueDescriptor.findForJsonType(String) to create the correct POJO implementation.
static String NAME
          The Metadata.getName() attribute of a JSON object.
static String VALUE
          The Metadata.getValue() attribute of a JSON object.
 
Method Summary
static void checkRequiredJsonAttribute(net.sf.json.JSONObject json, String attribute)
          Utility method for checking if a required attribute is present in the JSON object.
static net.sf.json.JSON toJson(Collection<MetadataValue> values)
          Converts the given values into a JSON array.
static MetadataValue toValue(net.sf.json.JSONObject json, MetadataContainer<MetadataValue> container)
          Converts the given JSON object to MetadataValue.
static List<MetadataValue> toValues(net.sf.json.JSONArray json, MetadataContainer<MetadataValue> container)
          Converts the given JSON array to MetadataValues.
static List<MetadataValue> toValues(net.sf.json.JSON json, MetadataContainer<MetadataValue> container)
          Converts the given JSON object to MetadataValues.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME

public static final String NAME
The Metadata.getName() attribute of a JSON object. Usually required.

See Also:
Constant Field Values

DESCRIPTION

public static final String DESCRIPTION
The Metadata.getDescription() attribute of a JSON object. Usually not required.

See Also:
Constant Field Values

METADATA_TYPE

public static final String METADATA_TYPE
The type of the metadata object mapped via AbstractMetadataValue.AbstractMetaDataValueDescriptor.findForJsonType(String) to create the correct POJO implementation.

See Also:
Constant Field Values

VALUE

public static final String VALUE
The Metadata.getValue() attribute of a JSON object. Usually required.

See Also:
Constant Field Values

CHILDREN

public static final String CHILDREN
The TreeNodeMetadataValue.getChildren() attribute of a node JSON object. Used instead of VALUE for nodes.

See Also:
Constant Field Values

EXPOSED

public static final String EXPOSED
The AbstractMetadataValue.isExposedToEnvironment() attribute of a node JSON object. Used to decide if this value should be exposed as an environment variable..

See Also:
Constant Field Values

GENERATED

public static final String GENERATED
The MetadataValue.isGenerated() attribute of a JSON object. Usually not required.

See Also:
Constant Field Values
Method Detail

toValues

public static List<MetadataValue> toValues(net.sf.json.JSON json,
                                           MetadataContainer<MetadataValue> container)
                                    throws JsonUtils.ParseException
Converts the given JSON object to MetadataValues. If the object is an array the method will return a list of them all else it will be a list of one items.

Parameters:
json - the JSON data to convert.
container - the container that the value is later supposed to go into. Can be used to check for validity of attributes.
Returns:
a list of converted values.
Throws:
JsonUtils.ParseException - if for example mandatory fields are missing in the data. The exception will contain the JSONObject that was the offending one.
See Also:
toValues(net.sf.json.JSONArray, MetadataContainer)

toValues

public static List<MetadataValue> toValues(net.sf.json.JSONArray json,
                                           MetadataContainer<MetadataValue> container)
                                    throws JsonUtils.ParseException
Converts the given JSON array to MetadataValues.

Parameters:
json - the JSON array to convert.
container - the container that the value is later supposed to go into. Can be used to check for validity of attributes.
Returns:
a list of converted values.
Throws:
JsonUtils.ParseException - if for example mandatory fields are missing in the data. The exception will contain the JSONObject that was the offending one.
See Also:
toValue(net.sf.json.JSONObject, MetadataContainer)

toValue

public static MetadataValue toValue(net.sf.json.JSONObject json,
                                    MetadataContainer<MetadataValue> container)
                             throws JsonUtils.ParseException
Converts the given JSON object to MetadataValue.

Parameters:
json - the JSON data to convert.
container - the container that the value is later supposed to go into. Can be used to check for validity of attributes.
Returns:
the converted value.
Throws:
JsonUtils.ParseException - if for example mandatory fields are missing in the data. The exception will contain the JSONObject that was the offending one, it could be something further down the hierarchy than the object provided..
See Also:
toValues(net.sf.json.JSONArray, MetadataContainer)

toJson

public static net.sf.json.JSON toJson(Collection<MetadataValue> values)
Converts the given values into a JSON array.

Parameters:
values - the values to convert.
Returns:
a JSON array.

checkRequiredJsonAttribute

public static void checkRequiredJsonAttribute(net.sf.json.JSONObject json,
                                              String attribute)
                                       throws JsonUtils.ParseException
Utility method for checking if a required attribute is present in the JSON object.

Parameters:
json - the object to check.
attribute - the attribute to check for.
Throws:
JsonUtils.ParseException - if the attribute is missing.


Copyright © 2004-2013. All Rights Reserved.