Search code examples
jsonjacksonwrapperjooq

How to convert Object to Jooq JSON


I have a String (jsonData) being mapped to json via Jackson Object mapper as below to JaxB.

var completeJson = objectMapper.readValue(jsonData, Data.class);
myDto.setFirstName(completeJson.getFirstName())
myDto.setLastName(completeJson.getLastName()))
.....
.....etc..etc

I'm able to map to the above strings just fine. However, I'm having problems mapping to a jooq JSON object. I guess I will now have to convert jsonData to jooq JSON.

How would I do this?

JSON newJson = objectMapper.(best method to use);

myDto.setJsonSource(newJson)
    

Or maybe I have to create some sort of wrapper?

DTO configured by jooq

public myDto setJsonSource(JSON jsonSource) {
    this.jsonSource = jsonSource;
    return this;
}

Solution

  • The org.jooq.JSON type is just a wrapper around a string, so why not just use:

    JSON json = JSON.json(objectMapper.writeValueAsString(object));