@homewantad opened this Issue on June 30th 2018

Hi there,

calling the bulk API provides different result structures between XML and json. I think the json format is actually wrong. Here is an example:

Calling: https://test.homewantad.com:943/?module=API&method=API.getBulkRequest, query segments for a VisitSummary, with period year for the last two years

urls[0]=method=VisitsSummary.get&idSite=1&period=year&date=last2&format=JSON&segment=pageU=^test.homewantad.com/ad/show/AWQh3OKzf2k4jhougDPr&urls[1]=method=VisitsSummary.get&idSite=1&period=year&date=last2&format=JSON&segment=pageUrl=^test.homewantad.com/ad/show/AWQx2EBr2vnhxw_A_uUe

The correct XML result structure is:

<result>
    <row>
        <row key="2017"></row>
        <row key="2018">...</row>
    </row>
    <row>
        <row key="2017"></row>
        <row key="2018">...</row>
    </row>
    <row></row>
</result>

The JSON structure does not match the xml structure (and has 3 problems, I think):

[{
    "2017": [],
    "2018": {
        "nb_visits": 1,
        "nb_actions": 45,
        "nb_visits_converted": 1,
        "bounce_count": 0,
        "sum_visit_length": 3396,
        "max_actions": 45,
        "bounce_rate": "0%",
        "nb_actions_per_visit": 45,
        "avg_time_on_site": 3396
    }
},
{
    "2017": [],
    "2018": {
        "nb_visits": 1,
        "nb_actions": 45,
        "nb_visits_converted": 1,
        "bounce_count": 0,
        "sum_visit_length": 3396,
        "max_actions": 45,
        "bounce_rate": "0%",
        "nb_actions_per_visit": 45,
        "avg_time_on_site": 3396
    }
}]

The following arguments are for an easy json to code mapping.

  • the whole json result structur is an array, it should be an json-object with an array inside like { [] }

  • the first json result-object has two fields. This is quitly difficult to map into a code representation. With an array instead, there are no problems:
    {[ { "2017" : { } ], [ { "2018" : { } ]} instead of { { "2017" : { } }, { "2018" : { } } }

  • the null representation for an object is {} or null, not [] in this context. [] is an empty array. An empty [] causes another problem for a dynamic mapping, when an object is expected and suddenly an array (empty) will be delivered.

With regards,
Dirk

@fdellwing commented on June 30th 2018 Contributor

Will just leave my thoughts about this:

The whole thing should be an JSON with an Array inside, not because it is really needed, but because thats what I exspect from an JSON API.

An empty value is not allowed to be [] if it will be an JSON with data.

So for me (coming from a JSONSimple context it would have to look like this:

{[
    {
        "2017": {},
        "2018": {...}
    },
    {
        "2017": {},
        "2018": {...}
    }
]}

So if you parse it, you will have an JSONObject (map) containing a JSONArray (list) containing JSONObjects (maps) containing JSONObjects (maps).

@homewantad commented on June 30th 2018

Almost that what I would expect:

JSONObject as "whole result" contains JSONObject (map) "result objects per bulk query" contains JSONObject (map) with "results objects per query, in my example the years" containing JSONObject (here Visit-class) with a field year and a object visit.

It's really a problem to map a field name "year" to a field of a class:

{ 
      "2017" : {},
     "2018" : {}
}

would be in Java:

class Visit {
       private 2017 visit;
       private 2018 visit;
}

I would expect

class Visit {
      private String year;
      private Visit visit;
}

and therefore a class Result with an Array of Visits as a field

private Visit[] visits.

When there are no results for a query, than [] is a zero result array and that's ok. When result of the query is only an object, than I would expect {} and not an empty array [].

Here the structure, that I would expect:

{[
    [ <---- here an array instead of a json object
        {     "year" : "2017", <--- that's correct, but as own object (one result object Visit for url[0])
                       "visit" : {}   
                },
        {      } <---- second result object for url[0]
    ],
    [
        {         }, <---- first result object for url[1]
        {         } <----- second result object for url[1]
    ],
        [] <----- no results for url[2] 
]}
Powered by GitHub Issue Mirror