On Mon, Apr 30, 2018 at 4:22 PM, Matthew Hall <[email protected]> wrote: > On Thu, Apr 26, 2018 at 3:16 PM, Tatu Saloranta <[email protected]> wrote: >> >> Deserializers ask `JsonParser`, either via `getText()` or one of >> variants (`nextTextValue()`). >> Decoding is handled by parser, possibly eagerly (when `nextToken()` is >> called), possibly lazily (implementation dependant) >> Converting from byte stream to tokens is what parser does, and not >> something deserializers have >> direct effect on. >> >> So you would need to reimplement parser to make it flexible enough, >> and figure out how to pass >> information on alternate encoding(s) somehow. >> >> -+ Tatu +- > > > Tatu, > > This advice is extremely helpful. > > Based on this, I first created a copy of ReaderBasedJsonParser, with all of > the "final" method labeling stripped off so that I can override them with > hacked versions. Then I made a subclass of that thing, with extra logic > hooking everything that's creating or returning some strings from buffers or > wherever, so that I can inserrt the dynamic encoding detection trickery. > > I have just one question left, about how to test or integrate this. The > constructors for these classes are somewhat internal-ish with some various > mysterious Jackson objects in them: > > public CustomJsonParser(IOContext ctxt, int features, Reader r, ObjectCodec > codec, CharsToNameCanonicalizer st, > char[] inputBuffer, int start, int end, boolean bufferRecyclable) { > super(ctxt, features, r, codec, st, inputBuffer, start, end, > bufferRecyclable); > } > > public CustomJsonParser(IOContext ctxt, int features, Reader r, ObjectCodec > codec, CharsToNameCanonicalizer st) { > super(ctxt, features, r, codec, st); > } > > I wanted to check where I should look for some examples how to construct > this custom parser on some test input, or how to hook it up to some other > existing ObjectMapper / JsonGenerator / JsonFactory sort of exterior > classes, so that I can run some input through my new code and learn how it > will crash. ;)
Right, these are not really defined as extension points. What might work better is defining `InputDecorator`, which you can register with `JsonFactory`. It will allow dynamic wrapping of passed-in `Reader` or `InputStream`. And then you don't have to worry about internal details of actually constructing parser instance. Approach may also work with other formats, whereas extending of factory directly would not. I hope this helps, -+ Tatu +- -- 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 [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
