The AllItemInventoryResult JSON object defines a page of all ItemInventory JSON Object results for the logged-in partner in the  DSCO system.

- Make sure you're familiar with JSON before continuing.
- The JSON objects are defined using Orderly.  Optional attrs end with a "?" all others are required.

- isodate fields use one of these ISO 8601 format: 2014-01-01T10:30:00.000+01:00, 2014-01-01T10:30:00.000+0100, 2014-01-01T10:30:00.000Z
- Dsco reserves the right to add new attributes at any time so Partners should ensure their validators won't break should this happen

Definition

This object will either have the itemInventory attribute set or it will have the base64EncodedCompressedItemInventory attribute set.

The  itemInventory attribute, if present, is the list of ItemInventory objects for this page of results.

The base64EncodedCompressedItemInventory, if present, is a base64 encoded string of the GZip compressed itemInventory results.  So, first decode this base64 string into a byte array and then decompress it using the gzip algorithm.  The result will be an array of ItemInventory objects.

If the pageIdentifier is not present or null then this is the last page of results.

If both the itemInventory attribute and the base64EncodedCompressedItemInventory attribute are both either not present or null then there are no more pages of results.

If either the itemInventory attribute or the base64EncodedCompressedItemInventory attribute (once unencoded and decompressed) are an empty list then there are no more pages of results.

Below you will find Java and NodeJS examples of decoding and uncompressing

Object
{
    string pageIdentifier;                   # Pass this in the next request to retrieve the next page
    array{ref ItemInventory} itemInventory?; # The page of item inventory results
    string base64EncodedCompressedItemInventory?; # Compressed, base 64 encoded itemInventory results
};

Example

{
    "pageIdentifier": "2342234242",
    "itemInventory":
    [
        <ItemInventory>,
        <ItemInventory>
    ]
}

Java Decode/Decompress Example

// The Base64 object below comes
// from the org.apache.commons.codec.binary package.
// The GZIPInputStream comes from java.util.zip package.
// The ItemInventory class defines the attributes documented in the JSON.
// The jsonMapper var is an instance of the Jackson library's JsonMapper
// The TypeReference class comes from the Jackson library

// Assume the base64EncodedCompressedItemInventory has been
// placed in this variable.
String encodedStr = null;

if (encodedStr != null) {                    
    byte[] decodedBytes = Base64.decodeBase64(encodedStr);
    ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
    GZIPInputStream gis = new GZIPInputStream(bis);
    BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
    StringBuilder sb = new StringBuilder();
    String line;
    while((line = br.readLine()) != null) {
        sb.append(line);
    }
    br.close();
    gis.close();
    bis.close();
    
    List<ItemInventory> list = jsonMapper.readValue(sb.toString(), 
                               new TypeReference<List<ItemInventory>>(){});                    
}

Node JS Decode/Decompress Example

// Using the zlib library to decompress gzipped data
const zlib = require('zlib');

// Assume that obj is AllItemInventoryResult JSON object
const str = obj.base64EncodedCompressedItemInventory;

if (str) {
    let buffer = new Buffer(str, 'base64');
    let decompressedData = [];
    let decompressor = zlib.createGunzip();
    decompressor.write(buffer);
    decompressor.end();
    decompressor.on('data', function(d) {
        decompressedData.push(d);
    });
    decompressor.on('error', function(e) {
        reject(e);
    });
    decompressor.on('end', function() {
        let itemInventoryStr = decompressedData.join('');
        let itemInventoryJson = JSON.parse(itemInventoryStr);

        console.log(JSON.stringify(itemInventoryJson));
    });
}
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.