-
Notifications
You must be signed in to change notification settings - Fork 185
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
Added JsonHelper class to convert Java/JSON #59
base: master
Are you sure you want to change the base?
Conversation
See the error. This project supports Java 5. |
Java 5, oh wow. Didn't knew that was still around. I removed the |
Hi Kristian, I know this kind of utilities from my own practice and I have to say that I try to eliminate them wherever possible as they're contrary to the idea of minimal-json, that is, to work with an efficient and complete Java representation of JSON data without having to make those "best guesses". They are indeed only guesses, in particular, you can't be sure that a JSON number is a valid Java Integer (it may be floating point, scientific notification, or exceeding A Java to Json converter can only handle some basic types, as soon as it gets to an object of any other type, it would fail–or, as in your case, replace it with Having that said, I guess that those helpers are sometimes necessary for compatibility with old systems, maybe also for cases that I'm currently missing... What is your typical use case? |
I don't want this to pass (I can't see it as part of minimal-json). But just in case it does, in line 59 you could pass the array size to the ArrayList's constructor. As this is a library, performance bottlenecks have a multiplicative factor. |
Hi Ralf, Hi Bernardo, Thanks a lot for your input. First of all, I fully support your opinions. minimal-json is neither a object mapper, nor the perfect "object mapping" library, but it is one of my favorite Java libaries when it comes to JSON parsing! It's no humongous framework, it's nice and simple, as it needs to be. Nevertheless I see a point in adding such a functionallity to the library, but let me tackle your concerns first.
Fully agreed, I added
Agreed. Especially for numbers, this is bad, because Java doesn't provide a direct equivalent. My suggestion would be to add a Ok, let me come to the reasons, which in my opition, speak for adding such a functionallity to the library:
I'm open for your feedback and it's fully in your decision if you support my idea or not, but I really think a similar functionallity would only benefit your library, as there is nothing bad about it. I can imagine the Thanks & regards, Kristian |
About your 3 reasons:
Not it is not. But many developers are not good enough to write this properly.
Yes. This is the single solid reason for doing it for me. Peer review and fix it in one place and let everyone use and improve this version.
Too much hype. Vanilla Java will still be around and strong in 2020.
No it won't.
Adding stuff has a cost. I am not talking about money directly, but if you give me 10 public classes I will take some time to figure out what your library does. If you give me 50 it will take more than that, and my wage is proportional to working time. Won't stand against you in this. Whatever Ralf decides is OK for me. |
Hello Bernardo, Thank you for correcting my spelling mistakes. Would you like to comment on my grammar as well? ;)
But hey, you do some typos as well, so touché.
I don’t think that's part of this discussion, but in my opinion there is nothing like “Vanilla Java”, a programming language which doesn’t evolve is a dead language. So Java evolves, so does C++, so does...
What?! How is it on you to judge that? I was asked for my opinion by Ralf, and this was my feedback. Feel free to accept or decline it, but judging about it, is very disrespectful in my eyes.
I agree, therefore I suggested adding an Thanks & regards, Kristian |
Yeah, you got me.
I didn't mean to disrespect. I just wanted to show my disagreement on a statement that is really strong (implies that the library is not useful for reading JSON data, which is its main - and sole? - purpose). The |
Without discussing pro and contra of such an API, here are some unsorted thoughts about a possible implementation:
|
In my implementation there is a similar helper class, but it's a bit different because I map JSON to Pojos. So the user decides (for example) if a JsonValue is a Or you have to go the json.org approach and provide |
@kristian With the new streaming API to be published in 0.9.5, wouldn't it be a better option to use a custom |
@ralfstx Sure, I see that as an alternative. Especially if such a |
Hey Ralf. Often I used to work with Java collections / maps and wanted to parse them to JSON. Therefore I added a JsonHelper class, performing a best-guess conversion from Java to JSON and vice-versa. Please let me know if you could imagine merging the request, if so, I would add some documentation.
In
jsonValueAsObject
, onlyint
numbers are supported, as with your implementation, you can't figure out what kind of number is in the JsonValue object.value.isNumber()
is not spcific enough. Similar toasString
, aasNumber
method would be helpfull returning a JavaNumber
object.