[json-processing-spec users] Re: convenient method to stringify json objects
- From: Tatu Saloranta <
- Subject: [json-processing-spec users] Re: convenient method to stringify json objects
- Date: Sun, 8 Apr 2012 09:38:58 -0700
On Sat, Apr 7, 2012 at 2:19 PM, Christian Grobmeier
> On Sat, Apr 7, 2012 at 11:13 PM, Tatu Saloranta
>>> A possible implementation could be:
>>> JsonObject obj ...
>>> obj.write(new StreamingGenerator(OutputStream));
>>> MemoryGenerator mg = new MemoryGenerator();
>>> Or something like that.
>>> Is this whats in your mind?
>> Right, this is one possibility. Another is to require external object
>> to combine the pieces. And perhaps there are others; but these seem
>> obvious ones.
>> One benefit of method you describe above is that this way one could
>> create custom node types, and override serialization method.
> Yap. One drawback is, I need the getResult() method on MemoryGenerator
> but not on the StreamingGenerator.
> It somehow feels wrong: is it included in the Generator interface, is
> it understandable for most people but senseless in the
> StreamingGenerator. Isn't it there, people might get confused because
> they need to cast to MemoryGenerator to get their result.
Oh, sorry, actually I should have read the code better. I do not think
there should be 'getResut()', as much as write just resulting in
underlying destination getting JSON content written.
And then that destination is responsible for handling;
StringWriter.toString() or so forth.
-+ Tatu +-