contentful / contentful.java

Java SDK for Contentful's Content Delivery API
https://contentful.github.io/contentful.java/
Apache License 2.0
74 stars 49 forks source link

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

Open scarySpice opened 1 month ago

scarySpice commented 1 month ago

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 commented 1 month ago

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

rafalniski commented 1 month ago

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.
leonardo-nickel commented 1 month ago

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!

rafalniski commented 1 month ago

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

leonardo-nickel commented 1 month ago

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

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