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.

4
  • 1
    isn't as easy as adding some quotes around the string ? "{'age': 35, 'job': 'engineer'}" ? ... i didn't try it though Commented Apr 11, 2016 at 13:07
  • What about Map<String, Object> data? A specific bean holding the age and job properties could be better. Commented Apr 11, 2016 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. Commented Apr 11, 2016 at 13:31
  • related: stackoverflow.com/questions/8137060/…, stackoverflow.com/questions/4783421/… Commented Apr 11, 2016 at 13:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.