This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new d5708936 Allow for null/nil as a scalar JSON value
d5708936 is described below

commit d5708936a8fbf3b3f6adc0bb0f556da15db5e122
Author: Sebb <[email protected]>
AuthorDate: Wed Jun 5 10:54:51 2024 +0100

    Allow for null/nil as a scalar JSON value
---
 lib/whimsy/asf/json-utils.rb | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/whimsy/asf/json-utils.rb b/lib/whimsy/asf/json-utils.rb
index 56d9285b..d433f113 100644
--- a/lib/whimsy/asf/json-utils.rb
+++ b/lib/whimsy/asf/json-utils.rb
@@ -13,18 +13,16 @@ module ASFJSON
     bc ||= ['root']
     h1.each do |k, v1|
       v2 = h2[k]
-      if v2.nil?
+      if !h2.include? k
         yield [bc, 'Dropped', k, v1]
       elsif v1 != v2
         case v1.class.to_s
-        when 'String', 'Integer'
-          yield [bc, 'Scalar', k, [v1, v2]]
         when 'Array'
           yield [bc, 'Array', k, [v1, v2]]
         when 'Hash'
           self.cmphash v1, v2, [bc,k].flatten, &block
-        else
-          raise ArgumentError.new "#{bc.join('.')} #{k} Unexpected class 
#{v1.class}"
+        else # treat as scalar
+          yield [bc, 'Scalar', k, [v1, v2]]
         end
       end
     end
@@ -77,4 +75,5 @@ if __FILE__ == $0
   out = StringIO.new
   ASFJSON.compare_json(old_json, new_json, out=out)
   puts out.string
+
 end

Reply via email to