2

I'm using a file containing JSON to configure the internals of my application. I'd like to be able to configure my values with, say, system properties and do variable substitution on them when unmarshalling the JSON.

The templating portion I have written it wasn't a big deal. What I'm trying to figure out is the best way to plug it in to my ObjectMapper.

From looking around, I think the best place would be in a JsonParser.getText method, but I can't seem to find any sane way to do this.

Here's a snippet example of what I'm trying to do. Basically I need to resolve the property before it gets deserialized.

I throw the Path example in there because previously I was naively performing this on the setters of the POJO which caused the JDK7Module's Path deserialization to lose its mind (it didn't like the :)

[
 { "name": "${sys:NAME}",
   "path": "${sys:ROOT}"
 }
]
Brian
  • 2,253
  • 2
  • 23
  • 39
  • String replace will do it right? – Madhan Jun 24 '15 at 18:07
  • It's not the replacement that's the problem it's where to hook it into jackson. I used Matcher to do the actual work and that is simply done. Unfortunately, because of things like nio.Path I have to do the replacement during the deserialization to the raw input stream or reader that's being passed it. Which actually gives me an idea ;) Thanks! – Brian Jun 25 '15 at 11:34

1 Answers1

0

I ended up creating a property resolving FilterInputStream. As I was deserializing the JSON from a file in my code I had this luxury.

Used this for inspiration but had to fully implement it and do it in a slightly different way due to varying token sizes:

Filter (search and replace) array of bytes in an InputStream

I'm still eager to hear any ideas on how this could get stuck into Jackson's normal flow as this may be something I want to extend to JAX-RS flows and I'm not certain I'd have access to wrap those input streams - though I imagine I could find the hooks in that API to do so.

Community
  • 1
  • 1
Brian
  • 2,253
  • 2
  • 23
  • 39