TYPO3-Headless / headless

TYPO3 Headless JSON API providing content for PWA application (e.g. javaScript apps like nuxt-typo3)
https://t3headless.io
GNU General Public License v2.0
160 stars 61 forks source link

Option for JSON to return null instead of empty array #709

Open kitzberger opened 8 months ago

kitzberger commented 8 months ago

In 2.x and (behind a compatibility feature flag) in 3.x it was possible to let the JsonContentObject (JSON) return null instead of an empty array.

I'd like to propose a new flag ifEmptyReturnNull for that JSON cObject. A flag with that name is already present for rendering the fields, which is cool and should be kept that way!

lib.test = JSON
lib.test.fields {
  propertyOne = TEXT
  propertyOne.value =
  propertyOne.ifEmptyReturnNull = 1
}

Here's an example to back my proposal: JSON's always rendering an empty array instead of the IMHO more correct null in case no record can be fetched:

lib.test = JSON
lib.test {
  dataProcessing.10 = FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor
  dataProcessing.10 {
    table = ....
    fields {
      propertyOne = TEXT
      propertyOne.field = header
      propertyOne.ifEmptyReturnNull = 1
    }
    returnFlattenObject = 1
    # That's the new flag!
    ifEmptyReturnNull = 1
  }
}
twoldanski commented 8 months ago

@kitzberger in 4.x by default dataProcessing is returning null instead of array, no flag needed, flag was meant for already built apps only so they won't break