On Wed, Oct 3, 2018 at 7:38 AM, Tatu Saloranta <t...@fasterxml.com> wrote: > On Tue, Oct 2, 2018 at 10:34 PM Nilson Santos Figueiredo Jr. > > I have a particular use-case where we're trying to optimize some code which > > uses Jackson to generate less garbage. > > The desired outcome here is to do something similar to what > > com.fasterxml.jackson.databind.ser.std.RawSerializer does, but avoiding the > > toString() conversion. > > Everything is working fine, except I can't avoid the duplication of byte[] > > buffers due to not having access to the private _writeBytes - I either need > > to convert those to char[] or to String. This is of course not ideal, as it > > then becomes a source of garbage. > I am not sure I follow exactly what you are attempting to do here, so > could you give an example of hypothetical calls you would make? > What kind of input would come in as byte[], other than binary data to > be base64 encoded?
Sure - I basically want to do exactly what JsonGenerator.writeRaw(char[] cbuf, int offset, int len) does, but with a byte[] buffer instead. The source of this byte[] is from a previous HTTP call to somewhere else, so it's already allocated. With the current API, I'd need to either create a new String or convert the byte[] to char[], both of which would required further allocations, which is specifically what I'm trying to avoid. The exact context is that this is a middleman service which gets JSON from some other service does some basic processing, but returns large chunks of this JSON to the caller unchanged. I currently have a workaround in place which is less than ideal: 1) create JsonGenerator based on some OutputStream; 2) write some stuff using JsonGenerator methods (writeStartObject, WriteXXXField, etc); 3) JsonGenerator.flush(); 4) write remaining stuff directly to the underlying OutputStream; 5) Call JsonGenerator.writeEndObject() So I want to inject arbitrary content in the middle of the JSON output and I need to do it generating little to no additional garbage. -Nilson -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscr...@googlegroups.com. To post to this group, send email to jackson-user@googlegroups.com. For more options, visit https://groups.google.com/d/optout.