-
Notifications
You must be signed in to change notification settings - Fork 24
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
Comment storage and formatting options #13
base: master
Are you sure you want to change the base?
Conversation
This is really cool, thanks for putting so much work into this PR. I think if possible we should keep the Java minimum requirements the same, especially if it's just one line of code that needs to change. I haven't written Java in several years so I can't help you with Java-specific features very much. Also, before I merge this code, I would like those bugs you identified to be fixed. I'll take a look and suggest some changes in the code when I get time later. And finally, I think that we should try to keep the features standardized with the other implementations when possible. So the |
Sure thing. Sorry for taking so long. I had just started training at a new job and wound up busy for a while. I've made the following changes:
The other issues I was mentioning are not really bugs, so much as minor inefficiencies that I would have preferred to avoid, but still have not had the time to really figure out. I also see that a series of unit tests regarding Moving forward, I could look into retaining whitespace between fields, but it may be a while before I'm able to start working on that due to work and other projects. Please let me know how you would like to proceed or any other thoughts you have. |
Well congrats on the new job first off! Work's been busy for me too, but I've finally found some good time to catch up on all my open source stuff. I just pushed a couple commits - one to allow users to configure if commenting is enabled or not, in part to fix some of the tests on Travis CI. The other just disables Also, it looks like a few bugs were introduced to do with object key/value commenting, array flattening, and a weird divide by zero case. I'll take a look at these later. |
Sure thing. Sounds great! I may be able to look into some of these issues this weekend, as well. Not sure where the divide by zero case could be occurring, though. And thanks! |
I may have inadvertently fixed the divide by zero issue. I'm still not sure what caused it, but I no longer see it in the unit tests on Travis CI. There is still one ParseException, reporting Edit: I have fixed the ParseException. Had no idea that commas before values on new lines was a part of the spec. ¯\(ツ)/¯ At this point, there are three main holdups:
I will be changing the original tests to account for these differences. Let me know if you have any objections, of course, and I'll continue to work around them. Edit 2: I have finished updating all formatting changes to the tests, all of which are passing now for jdk8. The jdk7 tests are reporting some pre-build type issue which appears to be unrelated to any changes I made. I'll try to take a look at that soon. Edit 3: Finished some code refactoring now that things are starting to look finished again on my end. Also added a new unit test specifically for comment support. It seems like the only hold up now is with the JDK7 error on Travis-CI, which as far as I can tell, seems to be related to support being phased for older JDK versions. I will most likely wait to hear from you before proceeding. |
PersonTheCat/hjson-java may continue to receive a small amount of support, but has largely been replaced by XJS.
I was working on another project using Hjson-java and realized it was missing a few things I needed. Namely, the ability to retain comments (my project uses them very liberally), as well as a few formatting options that I felt would make certain kinds of data a little bit more concise. So, I did just that. Here are some of the pros and cons that would be associated with merging this branch:
New Features
#
) symbol until the end of the current line. These do support multiple lines.//
). Like hash comments, these last until the end of the current line, but can technically be repeated on subsequent lines, with no issues./*
) and preceding a (*/
) and naturally can span multiple lines. Although users are free to include additional asterisks (*
) on subsequent lines, these will not be placed when formatted by hjson-java.JsonValue#setComment
or any of its variants, as well asJsonObject#set
,JsonObject#add
,JsonObject#setComment
or any of their variants, as well as the equivalent methods inJsonArray
.HjsonOptions
andHjsonWriter
.JsonObject#sort
.HjsonObjects
now returnthis
to enable chaining.Potential Cons
JsonObject#sort
relies onList#sort
, which requires a lambda expression. I did not see these used anywhere else in the code, so I suspect that this may increase the minimum Java requirements to version 8. This can of course be removed, however.JsonObject
andJsonArray
are not technically made immutable whenJsonObject#unmodifiableObject
or equivalent function is called. I'm not sure if this is a memory safety issue or more of just a measure intended to prevent the actual data contained by the objects from being changed. If this is an issue, please let me know how you would solve it, so I can make changes.HjsonWriter
. My workaround was to include an additional space at the end of the string when callingHjsonWriter#reset
. I'm not very happy with this solution.HjsonWriter#readBetweenVals
(replacement forskipWhiteSpace()
) to ignore the final new line character at the end of some comments. As a result, I wound up callingString#trim
on the value that gets returned. This is technically not ideal and, as such, I'm not very happy with that either.See it in Action
You can view this test input file to see almost everything I listed in-action. You can also view this output file which was generated by parsing a JsonObject from a file, adding a few new keys and comments, and finally serializing the new object to the disk.
And of course, if you do test this and discover any issues or notice anything right away that could be improved, please let me know and I may be able to work on it sometime soon.
-PersonTheCat
Edit: I see that the Travis CI build has failed due to an issue with using a lambda expression for
JsonObject#sort
. I'll wait to hear from someone else about whether this needs to be changed. Again, it could of course just be removed. See above.