Using Jackson

You can use two versions: Jackson 1.x from http://jettison.codehaus.org/ and Jackson 2.x from https://github.com/FasterXML/jackson.

Start by identifying SDK classes for the object returned by the service call. The example used here is the same as for Jettison, described in Using Jettison. It starts with adding the Micro Focus-provided ArcSight SDK classes:

// ArcSight SDK classes
import com.arcsight.product.manager.resource.service.v1.model.Group;
import com.arcsight.product.manager.resource.service.v1.axis2.jaxws.GroupServiceGetResourceByIdResponse;
    String responseBody = ... // that's what you get back from HTTP Request
    Class claz = GroupServiceGetResourceByIdResponse.class;
    ObjectMapper mapper = new ObjectMapper();
    // optional mapper configuration (see example below)
    // mapper.setPropertyNamingStrategy(new WsapiNameStrategy());
    InputStream is = new ByteArrayInputStream(responseBody.getBytes("UTF-8"));
    GroupServiceGetResourceByIdResponse groupResponse
                = (GroupServiceGetResourceByIdResponse)mapper.readValue(is, claz);
    // Retrieve a member of response class Group
    Group group = groupResponse.getReturn()

Observe that the code is smaller than for Jettison. However, you might need to add mapper configuration for nonstandard cases.

Dealing with Uppercase Field Names

Field names in uppercase are used as is by Jettison (as part of Jersey) so that ESM will have the exact letter case in JSON responses.

For example, if your Java class has this member:

/** URI reference to this resource */
private String URI;

Then the returned JSON response would contain this entry:

"URI": "/All Cases/All Cases/Personal/admin's Cases",

Unfortunately, processing in Jackson would fail with this exception:

Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "URI" ...
...

This exception happens because Jackson expects field names in JSON to be in lowercase or camelStyle. There are several approaches to instruct Jackson how to map object names to JSON fields. Following is the simplest approach that creates an implementation of a class and use it with the Jackson mapper:

public static class WsapiNameStrategy extends PropertyNamingStrategy {
        private final Map<String, String> mapping;
 
public WsapiNameStrategy() {
            mapping = new HashMap<String, String>();
mapping.put("uri", "URI");
}
 
@Override
        public String nameForSetterMethod(MapperConfig<?> config,
AnnotatedMethod method, String defaultName) {
if (mapping.containsKey(defaultName)) {
return mapping.get(defaultName);
}
return super.nameForSetterMethod(config, method, defaultName);
}
}

Namespace Support

As described elsewhere in this guide, the ESM Service Layer APIs returns data in XML by default, but data can be returned in different formats specified on your requests. One available option is JSON (http://json.org/). For both formats (XML or JSON), the Service Layer APIs uses namespaces to distinguish similar-looking blocks of data that belong to resources and data that belong to services of different types.

Namespaces are a natural part of XML syntax, but there is no similar standard concept in JSON. To provide similar functionality, different JSON parsers use different solutions. Not all parsers have functionality analogous to XML namespaces.

To work with JSON, the Service Layer APIs uses jettison (http://jettison.codehaus.org/), which supports XML namespaces by using additional prefixes.

For example, the XML element

xmlns:ns7="http://ws.v1.service.resource.manager.product.arcsight.com/dashboardService/"
...
<ns7:currentSignature>
   <id>FztgORycBABDy1m0rly+irg==</id>
   <modificationCount>0</modificationCount>
</ns7:currentSignature>

will be represented in JSON as

"das.currentSignature" : { 
     "id" : "FztgORycBABDy1m0rly+irg==",
     "modificationCount" : 0
}

Here, the prefix das is associated with XML namespace

xmlns:ns7="http://ws.v1.service.resource.manager.product.arcsight.com/dashboardService/"

To be able to convert XML to JSON and back, Jettison uses additional mappings between JSON namespaces (das, as in the example) and standard XML namespaces. The mappings used by Jettison from the Service Layer APIs are provided in the table in Using Proper Namespaces).

With that in mind, to parse the response, you need:

With these two pieces, a parser (Jettison or Jackson) will prepare an object of the specified class populated with the data from JSON. You can then access the parsed data by simply calling get methods on that Java object. If you use Jettison to parse a response, you do not need anything else–Jettison uses the metadata from the class definition to perform parsing. For other parsers like Jackson, you would need to provide additional classes, Marshaller and Unmarshaller, that will help Jackson properly handle namespace prefixes. This approach uses the NAMESPACE_PREFIX_MAPPER property.