Oh. ObjectMapper does not have way to configure schemas. I was about to say you should find it from README at:

but alas it does not cover this basic question! (I’ll have to add it)

But: for anything that can vary on per-call basis, you will need to use ObjectReaderand ObjectWriter for configuration. So:

String props = mapper.writer(schema).writeValueAsString(pojo);
Pojo value = mapper.readerFor(Pojo.class)

and these classes allow other kinds of re-configuration as well. Plus they are fully thread-safe, reusable, all around better to use than ObjectMapper. :)

Written by

Open Source developer, most known for Jackson data processor (nee “JSON library”), author of many, many other OSS libraries for Java, from ClassMate to Woodstox

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store