bluelinelabs / LoganSquare

Screaming fast JSON parsing and serialization library for Android.
Apache License 2.0
3.21k stars 306 forks source link

Parse: File, URL, Reader, byte[], char[] #31

Closed talklittle closed 9 years ago

talklittle commented 9 years ago

Would be nice to be able to LoganSquare.parse() from the different sources allowed by Jackson's JsonFactory.

JsonFactory provides all of the following:

EricKuck commented 9 years ago

The reason I didn't include every option is because I'd like to keep my options open for switching to another JSON parsing backend if something better comes along down the road (of if I write my own, which I've been toying with the idea of). Jackson core is definitely the fastest available at the moment, but I'm sure there's room for improvement, especially if it's written with mobile in mind (which Jackson was not).

While I'm sure any future library will include support for Streams and Strings, I'm not totally sure they'll include support for URLs, Readers, etc. To me, adding support for the byte[] and char[] parameters seem reasonable, as I can't imagine another library not including support for those.

I'm not comfortable adding URL support, since it seems like adding that option would just encourage people to not use a proper networking library. No idea what Jackson uses internally, but I very much doubt it's in any way optimized for Android.

File objects can easily be passed in as Streams, so I'm not too concerned with that one. Do you know of any networking libraries that use Readers? Is there something about them that would make wrapping the Reader in a ReaderInputStream bad?

talklittle commented 9 years ago

Thanks for the answer. I think it is easy enough to work around this limitation using the appropriate InputStreams like FileInputStream as you've indicated. Good idea to keep the implementation flexible to different parser backends. I'll close this issue.

EricKuck commented 9 years ago

Reopening it to remind me to add byte[] char[] support :)

Thanks for all these ideas for enhancements, btw! It's been super helpful.

EricKuck commented 9 years ago

b5dbe848059a73bbf35bd1f40cb7693578b102c4