contentful.java icon indicating copy to clipboard operation
contentful.java copied to clipboard

Transform query annotations; Mismatch of API response and com.contentful.java.cda.rich.CDARichDocument

Open scarySpice opened this issue 1 year ago • 5 comments

When you make an api call to receive an entry with a rich Text field inside, the response looks like this: image

When you receive a RichText field via java through .observeAndTransform() and you try to serialise , you get this image

There is no way to receive the rawJson representation of richText unless you manually process the object and that means you cannot annotate all the entries when there is a RichText field.

scarySpice avatar Oct 24 '24 16:10 scarySpice

We wish there was an annotation where we could mark a field to return the rawData you know? Like we don’t wanna any transformation, give me back the rawField representation and I’ll take from here

scarySpice avatar Oct 24 '24 16:10 scarySpice

Hey @scarySpice

that's something that we will consider adding in the future. Right now, I can think of two workarounds:

  1. Use the rawFields map in CDAEntry to directly access the raw JSON structure of richText fields. Here’s a quick example:
        final CDAEntry entry = client.fetch(CDAEntry.class)
            .include(10)
            .one(ENTRY_ID);
        Map<String, Object> richDocuments = (Map<String, Object>) entry.rawFields().get(FIELD_NAME);
        return richDocuments.get(DEFAULT_LOCALE);
  1. Alternatively bypass the library transformation by using a direct HTTP request to the Content Delivery API, which returns the raw JSON data.

rafalniski avatar Oct 25 '24 10:10 rafalniski

Hey @rafalniski ,

Thanks for the reply. @scarySpice and I are working together on this issue.

Currently we use Unwrapping feature where we map Contentful response into our own models using @TransformQuery.ContentfulField and @TransformQuery.ContentfulEntryModel. I'm guessing there's no way we could get back the rawFields with this approach?

In a different use case we do use the CDAEntry you've mentioned above with rawFields so yeah, that's an option but we'd need to move away from Unwrapping and I was just wondering whether there was an alternative without having to do that.

Thanks!

leonardo-nickel avatar Oct 25 '24 10:10 leonardo-nickel

So right now, there is no way to get rawFields with unwrapping, unfortunately.

rafalniski avatar Oct 25 '24 11:10 rafalniski

So right now, there is no way to get rawFields with unwrapping, unfortunately.

Alright, thanks for letting us know @rafalniski, appreciate the quick reply!

leonardo-nickel avatar Oct 25 '24 11:10 leonardo-nickel