Skip to Content
1
Aug 25, 2012 at 01:48 PM

Create Deep EntitySet and JSON

606 Views

I am using SAPUI5 and I am able to insert an Inline Data Feed when the data is formatted as XML, but face multiple issues when setting JSON to true. I believe this is not a SAPUI5 issue but a Gateway issue.

The entity i am posting has a 0:N relationship with the child entities.

The first thing i found was that i needed to have the array of child entities I am posting wrapped around a 'results' object. Not sure why SAPUI5 (Datajs) didn't do this.

eg.

{ "results": [ child1, child2 .. childn ]}

/IWCOR/CL_DS_EP_READER_JSON->/IWCOR/IF_DS_EP_READER~READ_ENTITY_SET

...IF lv_standalone = abap_true.       json_start.       read_count_and_next(         EXPORTING           io_reader      = io_reader         IMPORTING           ev_inlinecount = ev_inlinecount           ev_next        = ev_next ).       json_array gc_results. <<this lineELSE.

This appears consistent with http://www.odata.org/documentation/json-format-> 7. Representing Entries definition of OData V2

However when i manually wrap the 'results' object around the array, the parser triggers an exception way before, it is expecting an array to be associated with the navigation property not an object.


/IWCOR/CL_DS_EP_READER_JSON->READ_ENTITY_INTERNAL

..  " 3. "NavigationPropertyName":...  " Options:  " 1. "nav":{ "__deferred" :  " 2. "nav":[ - inline feed  " 3. "nav":{ - inline entry  io_reader->current_node( ).  IF io_reader->name = 'array' ##NO_TEXT. "  2. "nav":[ - inline feed    IF ld_nav_property->multiplicity <> /IWCOR/if_DS_edm=>gc_multiplicity_many.      RAISE EXCEPTION TYPE cx_sxml_parse_error        EXPORTING          xml_offset = io_reader->get_byte_offset( ).    ENDIF...

This would have been the logic for OData V1.

Further down the exception is triggered when it doesn't like the 1:N multiplicity.

ELSE.." 3. "nav":{ - inline entry IF ld_nav_property->multiplicity = /IWCOR/if_DS_edm=>gc_multiplicity_many.      RAISE EXCEPTION TYPE cx_sxml_parse_error          EXPORTING             xml_offset = io_reader->get_byte_offset( ).ENDIF.

Has anyone else come across this, is there a workaround or pending fix.

Cheers

John P

UPDATE: Just found Note 1751991 - OData Channel - Deep Insert in JSON Format Leads to Error which looks like it addresses this issue.