Create json object of undefined content
<p>I am working with an exiting API that expects a "Metadata" field as part of its json payload. That "Metadata" field is a json object that is completely free-form. Currently, I need to read this data provided from another source, do some enrichment, then pass it on. I am struggling with how to define this "Metadata" object so that it can be any valid json object. OR, if that field was not provided, an empty json object.</p>

<p>I attempted to use org.json.JSONObject like so.</p>

<pre><code>//meta is the json string read from the db
JSONObject jsonobject = new JSONObject(meta);
message.Metadata = jsonobject;
</code></pre>

<p>However, jackson, not unexpectedly, threw a serialization error:</p>

<pre><code>com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.json.JSONObject and no properties discovered...
</code></pre>

<p>This is a critical requirement that I'm guessing I am missing some relatively obvious solution to. Any help would be greatly appreciated.</p>

<p><strong>UPDATED FIX</strong></p>

<p>As suggested by @shmosel I just switched the json object to a com.fasterxml.jackson.databind.JsonNode and all works beautifully.</p>

<p>// working code (rough of course)<br>
ObjectMapper mapper = new ObjectMapper();</p>

<pre><code>JsonNode rootNode = null;
try {
       rootNode = mapper.readTree(meta);
    } catch (IOException e) {
       e.printStackTrace();
    }

message.Metadata = rootNode;
</code></pre>