-
Notifications
You must be signed in to change notification settings - Fork 333
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
Fix an issue with generate_pretty and empty objects in the Ruby and Java implementations #449
Conversation
61efee1
to
f5916bd
Compare
Also fixes #440 now. |
lib/json/pure/generator.rb
Outdated
} | ||
depth = state.depth -= 1 | ||
result << state.object_nl | ||
result << state.indent * depth if indent | ||
unless count.zero? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use unless first
to handle this instead of adding count
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't quite sure about what the 'object' could be and wether it was possibly an enumerator that can only run once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first == true
is always equivalent to count == 0
, isn't it? (they're modified together in the current diff)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see what you mean! Yes I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - I thought you were suggesting I called .first
on the contents.
89001db
to
31b9817
Compare
…ava implementations
31b9817
to
b8c1c64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@hsbt Could you review and merge?
It would be helpful to give a JRuby contributor write access to this repository, if this is where we will continue to manage the json extension. That person should probably be me. |
|
||
final boolean[] firstPair = new boolean[]{true}; | ||
object.visitAll(new RubyHash.Visitor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for the patch, but it's now constructing two objects instead of one. Making this an inner class with an accessible firstPair field would get it back down to one object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, read it out of the object field, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turned out to be quite a lot of refactoring to make the field accessible, as the local holding the visitor needs a new named class or interface in order to be able to read a field out of it, so I didn't do this change. I don't know if you want to @headius? Otherwise I'll leave it as is.
I believe this has not been released yet... so I am requesting a release! We were unable to resolve jruby/jruby#6338 in JRuby 9.2.14.0 because we do not ship prerelease code for default gems. |
Fixed #441.