You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Frédéric SOUCHU <Fr...@ingenico.com> on 2015/05/27 10:57:13 UTC

[OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only - works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action...

Regards,
Frederic