Gson @Expose equivalent in Java SDK?

Hey, i am not able to find a @Expose equivalent from Gson in Couchbase. In fact i did not find any information about annotations in general. Are there none or can someone refer me to them?
At least regarding JCBC-433 there should be no such document ( )

If there is no @Expose - what would the general approach be to save classes only partially. Create ContainerObjects implementing Serializable for every Class-File? Have a own .serialize() method for every class? Extend the PersistenceLayer with Class -> Map Code?

Using gson would mean unneeded re-converting
fromGson() -> String -> JsonObject.fromJson() -> (and internally the) transcoder.encode()

Any Tips? Is there a “best practice” document somewhere?


Hi @Kademlia,

the Java SDK in the released version does not support POJO to JSON mapping, like GSON or Jackson does. Currently, there are two ways to handle this:

  • You can use the JsonDocument with its JsonObject and JsonArray and you fill those objects on your own and then store it (so you are manually binding your POJO to JsonObject)
  • You can keep using GSON with your annotations and take the raw JSON string that is created and store it through the RawJsonDocument (which accepts the JSON string).

That should have you covered. That said, in the upcoming version we are working on exactly that feature: mapping your domain objects directly to JSON, without having to use a third party library. This is currently in the works and with the next developer preview (which is coming out soon), I’d appreciate any feedback you have there!

1 Like