Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JsonParser.Feature.* ? #29

Open
oschrenk opened this issue Feb 22, 2018 · 4 comments
Open

Using JsonParser.Feature.* ? #29

oschrenk opened this issue Feb 22, 2018 · 4 comments

Comments

@oschrenk
Copy link

Is there currently a way to enable features such as JsonParser.Feature.ALLOW_TRAILING_COMMA (this is how you know I have to deal with malformed json)?

@oschrenk oschrenk changed the title Using JsonParser.Feature.* Using JsonParser.Feature.* ? Feb 22, 2018
@travisbrown
Copy link
Member

@oschrenk It's not currently possible off the shelf, but it also wouldn't be terribly difficult. I think this is something we'll want to add at some point, so if you have ideas or would like to discuss an implementation, that would be excellent.

@netvl
Copy link

netvl commented Feb 12, 2019

It is actually possible to do this, if you explicitly extend the necessary traits:

object CustomJacksonParser extends WithJacksonMapper with JacksonParser {
  mapper.configure(SomeFeatures.SOME_FEATURE, true)
}

Then you just use this object instead of the default io.circe.jackson object to parse JSON:

CustomJacksonParser.decode[YourType](input)

Although this does feel quite hacky.

@netvl
Copy link

netvl commented Feb 25, 2019

Apparently my above code only works for deserializer features, because circe creates a separate JsonFactory specifically to do parsing and does not use the mapper's own factory to do the parsing (just curious, what is the reason for this?), and this separate JsonFactory does not use features enabled in the original mapper. I see no other way around right now except for reflection.

@travisbrown
Copy link
Member

@netvl I'm not sure why there's a separate JsonFactory. I created this project as a port of Play JSON's Jackson parsing because there was demand for a Jackson-based circe parsing module, but I've never needed it for myself (or anyone who was paying me), so it's not received a huge amount of attention. I'll happily review any PRs, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants