json 2.14.1-java → 2.15.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2e31ae12a6d5034bd9ece1f72e955b04ab82b8ee182cfe12c0746742dcb0c3b
4
- data.tar.gz: 9fdeb6ef792a44b0ac7889c304d2ea5cec04b6a87717e81398e53492e764b945
3
+ metadata.gz: fb359285577cc6ca4fef3f2fab5951a061ddef62a61e5285ddb65dc669724b46
4
+ data.tar.gz: 52d9c6458373dcce01bb3617314d78866c50aebacdb3d3f57ad290a83d56bf5f
5
5
  SHA512:
6
- metadata.gz: 964c3d63ff720ff366b714c1cf0449a3ecb5066713f8229085d2ba5df1559f0e858e4ee97337ba0d4aa926eb1b70734c799f5a1f9bad804ae24bb6f4688d8b89
7
- data.tar.gz: fac0e89fa2d81a0ed82f08c7b70cbb39d319440c95f291f59ae95012d11e940080dc821a3cd19a5f093cae10ef696611e0924b49baf034f90cd39430606a6299
6
+ metadata.gz: 7d142aab3c9431a4bf29b980577203af8495d07a16e3249717c342041945b8e5e3a7343b14671efce0ceb6f65aa1f4eb465f03a1cc99a639b6fce09f16686e63
7
+ data.tar.gz: ee282d56a5f74a25f7597821d8c6de4b46fb09e976ebd3c3338eba678fbacd0d8d7888d7d3b6968645f7845e92bbec02cc84df44e0d2e135f52ad895496ff485
data/CHANGES.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2025-09-22 (2.15.0)
6
+
7
+ * `JSON::Coder` callback now receive a second argument to convey whether the object is a hash key.
8
+ * Tuned the floating point number generator to not use scientific notation as agressively.
9
+
5
10
  ### 2025-09-18 (2.14.1)
6
11
 
7
12
  * Fix `IndexOutOfBoundsException` in the JRuby extension when encoding shared strings.
@@ -23,6 +28,7 @@
23
28
  * Fix `JSON::Coder` to also invoke block for hash keys that aren't strings nor symbols.
24
29
  * Fix `JSON.unsafe_load` usage with proc
25
30
  * Fix the parser to more consistently reject invalid UTF-16 surogate pairs.
31
+ * Stop defining `String.json_create`, `String#to_json_raw`, `String#to_json_raw_object` when `json/add` isn't loaded.
26
32
 
27
33
  ### 2025-07-28 (2.13.2)
28
34
 
data/README.md CHANGED
@@ -97,7 +97,7 @@ Instead it is recommended to use the newer `JSON::Coder` API:
97
97
 
98
98
  ```ruby
99
99
  module MyApp
100
- API_JSON_CODER = JSON::Coder.new do |object|
100
+ API_JSON_CODER = JSON::Coder.new do |object, is_object_key|
101
101
  case object
102
102
  when Time
103
103
  object.iso8601(3)
@@ -113,6 +113,8 @@ puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
113
113
  The provided block is called for all objects that don't have a native JSON equivalent, and
114
114
  must return a Ruby object that has a native JSON equivalent.
115
115
 
116
+ It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`.
117
+
116
118
  ## Combining JSON fragments
117
119
 
118
120
  To combine JSON fragments into a bigger JSON document, you can use `JSON::Fragment`:
Binary file
Binary file
@@ -47,6 +47,14 @@ module JSON
47
47
 
48
48
  SCRIPT_SAFE_ESCAPE_PATTERN = /[\/"\\\x0-\x1f\u2028-\u2029]/
49
49
 
50
+ def self.native_type?(value) # :nodoc:
51
+ (false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
52
+ end
53
+
54
+ def self.native_key?(key) # :nodoc:
55
+ (Symbol === key || String === key)
56
+ end
57
+
50
58
  # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
51
59
  # UTF16 big endian characters as \u????, and return it.
52
60
  def self.utf8_to_json(string, script_safe = false) # :nodoc:
@@ -448,10 +456,10 @@ module JSON
448
456
  state = State.from_state(state) if state
449
457
  if state&.strict?
450
458
  value = self
451
- if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
459
+ if state.strict? && !Generator.native_type?(value)
452
460
  if state.as_json
453
- value = state.as_json.call(value)
454
- unless false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value
461
+ value = state.as_json.call(value, false)
462
+ unless Generator.native_type?(value)
455
463
  raise GeneratorError.new("#{value.class} returned by #{state.as_json} not allowed in JSON", value)
456
464
  end
457
465
  value.to_json(state)
@@ -509,12 +517,12 @@ module JSON
509
517
  end
510
518
  result << state.indent * depth if indent
511
519
 
512
- if state.strict? && !(Symbol === key || String === key)
520
+ if state.strict? && !Generator.native_key?(key)
513
521
  if state.as_json
514
- key = state.as_json.call(key)
522
+ key = state.as_json.call(key, true)
515
523
  end
516
524
 
517
- unless Symbol === key || String === key
525
+ unless Generator.native_key?(key)
518
526
  raise GeneratorError.new("#{key.class} not allowed as object key in JSON", value)
519
527
  end
520
528
  end
@@ -527,10 +535,10 @@ module JSON
527
535
  end
528
536
 
529
537
  result = +"#{result}#{key_json}#{state.space_before}:#{state.space}"
530
- if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
538
+ if state.strict? && !Generator.native_type?(value)
531
539
  if state.as_json
532
- value = state.as_json.call(value)
533
- unless false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value
540
+ value = state.as_json.call(value, false)
541
+ unless Generator.native_type?(value)
534
542
  raise GeneratorError.new("#{value.class} returned by #{state.as_json} not allowed in JSON", value)
535
543
  end
536
544
  result << value.to_json(state)
@@ -588,10 +596,10 @@ module JSON
588
596
  each { |value|
589
597
  result << delim unless first
590
598
  result << state.indent * depth if indent
591
- if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value || Symbol == value)
599
+ if state.strict? && !Generator.native_type?(value)
592
600
  if state.as_json
593
- value = state.as_json.call(value)
594
- unless false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value || Symbol === value
601
+ value = state.as_json.call(value, false)
602
+ unless Generator.native_type?(value)
595
603
  raise GeneratorError.new("#{value.class} returned by #{state.as_json} not allowed in JSON", value)
596
604
  end
597
605
  result << value.to_json(state)
@@ -625,7 +633,7 @@ module JSON
625
633
  if state.allow_nan?
626
634
  to_s
627
635
  elsif state.strict? && state.as_json
628
- casted_value = state.as_json.call(self)
636
+ casted_value = state.as_json.call(self, false)
629
637
 
630
638
  if casted_value.equal?(self)
631
639
  raise GeneratorError.new("#{self} not allowed in JSON", self)
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '2.14.1'
4
+ VERSION = '2.15.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.1
4
+ version: 2.15.0
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-18 00:00:00.000000000 Z
11
+ date: 2025-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A JSON implementation as a JRuby extension.
14
14
  email: dev+ruby@mernen.com