You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jackso...@googlegroups.com
Hello!
I'm using Jackson to consume data returned by the AdoptOpenJDK API [0].
This JSON doesn't contain type annotations, but I do know all of the
types ahead of time thanks to their publishing of a schema via Swagger.
I've defined the set of types published by the API:
However, for reasons of paranoia, I'd now like to configure the object
mapper such that the set of types it is allowed to deserialize is
fixed. In other words: A deserialization whitelist. Specifically, the
whitelist would look like this:
Additionally, I'd need one concrete List implementation, but I'm not
sure which that would be. I'm happy to use whatever Jackson is choosing
internally.
What is the most efficient way to set up this whitelist?
But if you want, you should be able to implement this relatively
easily by registering `Deserializers` (custom provider for
deserializers) that will verify that type for which deserializer is
needed is legit (class from list you define), and throws `Exception`
if not, return `null` if it is (to let default JsonDeserializer be
used).
Provider needs to be added by a `Module` using `ObjectMapper.registerModule()`.
Simplest way to do that would probably be to subclass
`SimpleDeserializers`, override `_find(JavaType)` method, then
construct `SimpleModule`, call `setDeserializers(...)`, register
resulting module.
I hope this helps,
-+ Tatu +-
Mark Raynsford
unread,
Mar 29, 2020, 10:42:58 AM3/29/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
Yep, this was the post I read originally but couldn't work out if it
applied to me. It seems like it doesn't, given that I can't get type
annotations into the input JSON.
> But if you want, you should be able to implement this relatively
> easily by registering `Deserializers` (custom provider for
> deserializers) that will verify that type for which deserializer is
> needed is legit (class from list you define), and throws `Exception`
> if not, return `null` if it is (to let default JsonDeserializer be
> used).
> Provider needs to be added by a `Module` using `ObjectMapper.registerModule()`.
>
> Simplest way to do that would probably be to subclass
> `SimpleDeserializers`, override `_find(JavaType)` method, then
> construct `SimpleModule`, call `setDeserializers(...)`, register
> resulting module.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Mark Raynsford, jackson-user
On Sun, Mar 29, 2020 at 7:42 AM Mark Raynsford
<list+com.faster...@io7m.com> wrote:
>
> On 2020-03-28T17:24:31 -0700
> Tatu Saloranta <ta...@fasterxml.com> wrote:
> >
> > Jackson does not have out-of-the-box support for whitelisting all
> > types allowed for general use; it only supports this for validating
> > polymorphic deserialization (which is explained f.ex in
> > https://medium.com/@cowtowncoder/jackson-2-10-safe-default-typing-2d018f0ce2ba).
>
> Yep, this was the post I read originally but couldn't work out if it
> applied to me. It seems like it doesn't, given that I can't get type
> annotations into the input JSON.
Right. And you really shouldn't, unless it is actually needed.
Static type safety has its benefits, esp. in preventing possibility of
attacker abusing types outside of your class definitions.
> > But if you want, you should be able to implement this relatively
> > easily by registering `Deserializers` (custom provider for
> > deserializers) that will verify that type for which deserializer is
> > needed is legit (class from list you define), and throws `Exception`
> > if not, return `null` if it is (to let default JsonDeserializer be
> > used).
> > Provider needs to be added by a `Module` using `ObjectMapper.registerModule()`.
> >
> > Simplest way to do that would probably be to subclass
> > `SimpleDeserializers`, override `_find(JavaType)` method, then
> > construct `SimpleModule`, call `setDeserializers(...)`, register
> > resulting module.
>
> Sounds good, thanks! I'll give it a shot.