2

I have a Spring REST controller that serializes an entity (default behaviour). For one of the fields of this entity I would like to save the actual Json (and not deserialize it).

For example:

Entity:

class Person:
  String name
  String data

Post to /person/1

{
  'name': 'John', 
  'data': {'age': 35, 'job': 'engineer'}
}

The default deserialization won't handle {'age': 35, 'job': 'engineer'} as a String value. It throws an exception (com.fasterxml.jackson.databind.JsonMappingException).

Is there a way to accomplish this easily? I prefer to not write my own serializer/deserializer.

codesmith
  • 1,381
  • 3
  • 20
  • 42
  • 1
    isn't as easy as adding some quotes around the string ? `"{'age': 35, 'job': 'engineer'}"` ? ... i didn't try it though – Pras Apr 11 '16 at 13:07
  • What about `Map data`? A specific bean holding the `age` and `job` properties could be better. – sp00m Apr 11 '16 at 13:09
  • @Pras: yes, that is easy, but not what we want. We would like to make it pure JSON outside of our application. – codesmith Apr 11 '16 at 13:31
  • related: http://stackoverflow.com/questions/8137060/jackson-deserialize-variable-as-json-string, http://stackoverflow.com/questions/4783421/how-can-i-include-raw-json-in-an-object-using-jackson – codesmith Apr 11 '16 at 13:32

0 Answers0