Uploaded image for project: 'Magnolia REST Framework'
  1. Magnolia REST Framework
  2. MGNLREST-227

Content Delivery API can produce invalid JSON

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.1.5
    • Fix Version/s: 2.1.6, 2.2.2
    • Component/s: None
    • Labels:
    • Release notes required:
      Yes
    • Epic Link:
    • Sprint:
      Maintenance 17, Maintenance 18, Maintenance 19, Maintenance 21
    • Story Points:
      5
    • Magnolia Release:
      6.2, 6.2.3

      Description

      The content delivery API produces invalid JSON when a reference resolver that is applied to a list returns Optional.Empty(). The issue is in info.magnolia.rest.delivery.jcr.NodeWriter#writeProperty:

                  for(int i = 0; i < values.length; ++i) {
                      String valueAsString = this.getValueString(values[i]);
                      if (isResolveReference && referenceResolver.isPresent()) {
                          Optional<Object> reference = ((ReferenceResolver)referenceResolver.get()).resolve(valueAsString);
                          if (this.canWriteReference(reference, stack, valueAsString, depth)) {
                              this.writeResolvedReference(jsonGenerator, reference.get(), (String)null, i > 0, stack, depth, annotations, entityStream, mediaType, httpHeaders);
                              resolvedValues.add(valueAsString);
                          } else if (resolvedValues.contains(valueAsString)) {
                              this.writeResolvedReference(jsonGenerator, reference.get(), (String)null, i > 0, stack, depth, annotations, entityStream, mediaType, httpHeaders);
                          } else {
                              // FIX THIS a common needs to added here if 'i > 0'
                              jsonGenerator.write(valueAsString);
                          }
                      } else {
                          jsonGenerator.write(valueAsString);
                      }
                  }
      

      See attached example of malformed json.
      The use case for this is as follows: We’re converting a JCR object that bundles together a set of amazon s3:// asset to a model with hyperlinks. The issue happens when the JCR object with the s3 links gets deleted, but orphaned references remain.

        Attachments

          Activity

            People

            Assignee:
            mdivilek Milan Divilek
            Reporter:
            lstaniorski Leah Staniorski
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Date of First Response:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 5.25d
                5.25d