1

I'm trying to figure out how to map a nested JSON string within a JSON string using jackson in a dynamic way as this is a library. So I have this method that handles mapping of results to objects

public <T> Flux<T> doStuff(Query query, Class<T> entityClass) throws DataAccessException {
    ... run query get row 
    Flux.just(objectMapper.readValue(row.asObject().toJsonString(), entityClass));
}

Unfortunately this is the structure of one of our users data:

{"abc":19220,"xyz":"{\"bla\": 123456}"}

The problem here is that the value for "xyz" is a json string. Is there any way or existing annotation for the users entityClass model to let jackson know that it should also deserialize the specific field "xyz"?

Here is the users model:

public class Something {
   @Id
   @JsonProperty("abc")
   public Abc abc;
   @JsonProperty("xyz")
   public Xyz xyz; // String would work here but we want to deserialize the value
}

The user does not have any way to modify the json to be correct so im wondering if there is anything we can do at the library level or anything the user can add to their entity class for jackson to work as we'd like it to?

andresmonc
  • 398
  • 7
  • 21
  • 2
    [This](https://stackoverflow.com/questions/66184698/how-can-i-deserialize-a-nested-wrapped-string-in-jackson) can help. – dariosicily May 16 '23 at 14:47

0 Answers0