restAPI Description, get newlines

Plone Description renders without newlines (returns), but they are saved.
Is there a way to get text WITH newlines from resAPI?

PS: I can 'search/replace' on the other side, so it could be 'any code' (//n, /n etc)

$ DOCUMENT_ID=$(\
    curl -s -X POST ${SITE_URL} \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    --data-raw '{"@type": "Document", "title": "My Document", "description": "first line\nsecond line"}' \
    --user ${USER} \
    | jq -r '."@id"'\
)

$ curl \
    -s -X GET ${DOCUMENT_ID} \
    -H "Accept: application/json" \
    --user ${USER} \
    | jq -r ".description"

first line
second line
1 Like

Not sure if I understand.
Are you saying that Plone actually 'sends the newlines'?

I fetch the data from my Plone site (in dart programming language) with

      final http.Response apiListing = await http.get(
    Uri.parse(
         'https://api.medialog.no/bergen/bergen/@search?portal_type=sted&metadata_fields=url&metadata_fields=rating&metadata_fields=longitude&metadata_fields=latitude&sort_on=sortable_title'),
    headers: <String, String>{
      'Accept': 'application/json,',
      'Content-Type': 'application/json'
    },
  );

But I can not see any 'newlines' in there. How can I 'check' ?

I did try with Postman, but after 'TRYKKSAKER' there is a newline in Plone, but in postman I think it has become a space

Wild guess: have you verified what is stored in the Description metadata column in portal_catalog for your document? This could be a case where what is stored on content differs from what is kept in the catalog?

You probably want to rule out (or in) the catalog storing some whitespace-normalized value of the Description — with a catalog search in a debug session using path to content, evaluate what is in the brain's Description attribute, like:

>>> brains = site.portal_catalog.unrestrictedSearchResults(
...     path='/MYSITE/path/to/content')
>>> print(repr(brains[0].Description))

Your REST-API is returning a description field with newlines when you get it directly from the content:

$ curl \
    -s -X GET \
    "https://api.medialog.no/bergen/bergen/grieg-medialog-as" \
    -H "Accept: application/json" \
    | grep "^  \"description"

  "description": "TRYKKSAKER: \r\nTotalleverand\u00f8r av grafiske tjenester, 
trykksaker og profilerings\u00adartikler\r\nNETTSIDER: Skreddersydde, profesjonelle 
nettsider / hjemmesider, design og webl\u00f8sninger,\r\nDESIGN: Alt fra logodesign, 
annonser, displaymateriell til reklametrykksake",

But when querying via @search you get a version without newlines:

$ curl \
    -s -X GET \
    "https://api.medialog.no/bergen/bergen/@search?id=grieg-medialog-as" \
    -H "Accept: application/json" \
    | grep "^      \"descript"

      "description": "TRYKKSAKER:  Totalleverand\u00f8r av grafiske tjenester, 
trykksaker og profilerings\u00adartikler NETTSIDER: Skreddersydde, profesjonelle 
nettsider / hjemmesider, design og webl\u00f8sninger, DESIGN: Alt fra logodesign, 
annonser, displaymateriell til reklametrykksake",

Querying via @search and fullobjects=1 you get the newlines:

$ curl \
    -s -X GET \
    "https://api.medialog.no/bergen/bergen/@search?id=grieg-medialog-as&fullobjects=1" \
    -H "Accept: application/json" \
    | grep "^      \"descript"

      "description": "TRYKKSAKER: \r\nTotalleverand\u00f8r av grafiske tjenester, 
trykksaker og profilerings\u00adartikler\r\nNETTSIDER: Skreddersydde, profesjonelle 
nettsider / hjemmesider, design og webl\u00f8sninger,\r\nDESIGN: Alt fra logodesign, 
annonser, displaymateriell til reklametrykksake",

When using @search you get a "summary" not the object itself. The serializer for the summary doesn't access the attribute description but the method Description:

The method Description replaces the newlines with spaces.

Thanks for the help.
I have not had the time to look at it yet (busy day), but I would 'kind of call it a bug', if the results are different (depending on how you fetch the data)?

PS: It is a default setup, so this would be the standard behaviour for the Description field.

UPDATE: Did a test, and just changing the below 'works'

FIELD_ACCESSORS = {
    "@id": "getURL",
    "@type": "PortalType",
    "description": "description",
    "title": "Title",

}

The rationale behind is to show the Description in summaries without new lines. This was probably meant as a feature.

IMHO suchreplacements should belong to a presentation layer not to a content layer.
If one wants it in a content layer this method could better have been named something like DescriptionWithoutLineBreaks instead of the misleading Description.

The REST-API has some endpoints with such a presentational perspective which obfuscate the content (see e.g. the handling of values in richtext fields).