intridea/multi_json

:json_common adapter doesn't define it's own ParseError

iainbeeston opened this issue · 2 comments

With most multi_json adapters, if I try to parse invalid JSON, a MultiJson::ParseError is raised. For example:

require 'multi_json'
MultiJson.use :json_gem
MultiJson.load("foo") # => raises MultiJson::ParseError: 795: unexpected token at 'foo'

However, the :json_common adapter raises a NameError:

require 'multi_json'
MultiJson.use :json_common
MultiJson.load("foo") # => raises NameError: uninitialized constant MultiJson::Adapters::JsonCommon::ParseError

This is because every adapter class defines a ParseError object (which MultiJson uses to catch parse errors - see here). However the :json_common adapter does not define it's own ParseError, leading to a NameError when MultiJson tries to access it.

It looks like defining a ParseError on the :json_common adapter would fix the issue (though what is the correct parse error class to catch?)

rwz commented

Actually, JsonCommon is not an adapter you should use. It's an abstract class and is there only so JsonGem and JsonPure can inherit from it.

We should probably communicate it somehow, I know it's confusing since it's sitting in the adapters folder with all other legit adapters.

Ah I wondered as much.