Web Connection
Returning with rest API an empty cursor
Gravatar is a globally recognized avatar based on your email address. Returning with rest API an empty cursor
  Michele
  All
  Jun 7, 2018 @ 07:57am

In my Rest class i have a function that create a cursor adapter object and select some records, then i return the result with cursor:cursorName

In the app that called the rest api i don't know how to work when the cursor adapter object didn't select any record because i don't receive any data and the json object is empty

Gravatar is a globally recognized avatar based on your email address. re: Returning with rest API an empty cursor
  Rick Strahl
  Michele
  Jun 7, 2018 @ 10:44am

An empty cursor produces an empty JSON array. So you are getting a response but no structure... so if you have to know that then you have to think of some other way like maybe explicitly adding an empty record to the Cursor before serializing and then checking for that - ie. check to see if htere's one record and it has all (or specific) empty fields that identity the cursor as 'empty'.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Returning with rest API an empty cursor
  Michele
  Rick Strahl
  Jun 7, 2018 @ 11:20am

This was the solution I was thinking to use but I had some problems with cursor adapter when using an object that takes data not from a table but form a view.... I'm using as backend data server PostgreSQL

Gravatar is a globally recognized avatar based on your email address. re: Returning with rest API an empty cursor
  Rick Strahl
  Michele
  Jun 7, 2018 @ 12:36pm

Well you need a Read/Write cursor. If necessary select from the result view and produce a READWRITE cursor that you can serialize and add that empty record to.

FWIW, the JSON serializer doesn't really support 2 way conversion of data anyway, so you must already have logic in place to deal with that (using CollectionToCursor()). Unlike XML, JSON doesn't have scheme to provide the structure so unfortunately some trickery is required to make dynamic cursor reconstruction work.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Returning with rest API an empty cursor
  Michele
  Rick Strahl
  Jun 7, 2018 @ 12:44pm

I already use CollectionToCursor function when i receive the json from my rest api class.Even the solution of creating a new cursor (ReadWrite) from the original i obtained from the cursoradapter is a good solution, but ihave to see if it increase responses time... Perhaps i can do it only when i have an empty cursor..

Thanks

© 1996-2024