Skip to content

Commit 3db5c87

Browse files
committed
Remove JSON::State#[] and JSON::State#[]=
1 parent b437d14 commit 3db5c87

4 files changed

Lines changed: 1 addition & 88 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Removed `JSON.load_default_options`.
99
- Removed `JSON.unsafe_load_default_options`.
1010
- Removed `JSON.dump_default_options`.
11+
- Removed `JSON::State#[]` and `JSON::State#[]=`.
1112

1213
### 2026-07-13 (2.21.1)
1314

java/src/json/ext/GeneratorState.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -270,30 +270,6 @@ public IRubyObject generate(ThreadContext context, IRubyObject obj) {
270270
return generate(context, obj, context.nil);
271271
}
272272

273-
@JRubyMethod(name="[]")
274-
public IRubyObject op_aref(ThreadContext context, IRubyObject vName) {
275-
String name = vName.asJavaString();
276-
if (getMetaClass().isMethodBound(name, true)) {
277-
return send(context, vName, Block.NULL_BLOCK);
278-
} else {
279-
IRubyObject value = getInstanceVariables().getInstanceVariable("@" + name);
280-
return value == null ? context.nil : value;
281-
}
282-
}
283-
284-
@JRubyMethod(name="[]=")
285-
public IRubyObject op_aset(ThreadContext context, IRubyObject vName, IRubyObject value) {
286-
checkFrozen();
287-
String name = vName.asJavaString();
288-
String nameWriter = name + "=";
289-
if (getMetaClass().isMethodBound(nameWriter, true)) {
290-
return send(context, context.runtime.newString(nameWriter), value, Block.NULL_BLOCK);
291-
} else {
292-
getInstanceVariables().setInstanceVariable("@" + name, value);
293-
}
294-
return context.nil;
295-
}
296-
297273
public ByteList getIndent() {
298274
return indent;
299275
}

lib/json/ext/generator/state.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,6 @@ def to_h
7171
end
7272

7373
alias_method :to_hash, :to_h
74-
75-
# call-seq: [](name)
76-
#
77-
# Returns the value returned by method +name+.
78-
def [](name)
79-
::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
80-
81-
if respond_to?(name)
82-
__send__(name)
83-
else
84-
instance_variable_get("@#{name}") if
85-
instance_variables.include?("@#{name}".to_sym) # avoid warning
86-
end
87-
end
88-
89-
# call-seq: []=(name, value)
90-
#
91-
# Sets the attribute name to value.
92-
def []=(name, value)
93-
::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
94-
95-
if respond_to?(name_writer = "#{name}=")
96-
__send__ name_writer, value
97-
else
98-
instance_variable_set "@#{name}", value
99-
end
100-
end
10174
end
10275
end
10376
end

test/json/json_generator_test.rb

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ def test_states
287287
json = generate({1=>2}, nil)
288288
assert_equal('{"1":2}', json)
289289
s = JSON.state.new
290-
assert s.check_circular?
291-
assert_deprecated_warning(/JSON::State/) do
292-
assert s[:check_circular?]
293-
end
294290
h = { 1=>2 }
295291
h[3] = h
296292
assert_raise(JSON::NestingError) { generate(h) }
@@ -299,10 +295,6 @@ def test_states
299295
a = [ 1, 2 ]
300296
a << a
301297
assert_raise(JSON::NestingError) { generate(a, s) }
302-
assert s.check_circular?
303-
assert_deprecated_warning(/JSON::State/) do
304-
assert s[:check_circular?]
305-
end
306298
end
307299

308300
def test_falsy_state
@@ -578,35 +570,6 @@ def to_s
578570
bignum.class.define_method(:to_s, original_to_s) if original_to_s
579571
end
580572

581-
def test_hash_likeness_set_symbol
582-
assert_deprecated_warning(/JSON::State/) do
583-
state = JSON.state.new
584-
assert_equal nil, state[:foo]
585-
assert_equal nil.class, state[:foo].class
586-
assert_equal nil, state['foo']
587-
state[:foo] = :bar
588-
assert_equal :bar, state[:foo]
589-
assert_equal :bar, state['foo']
590-
state_hash = state.to_hash
591-
assert_kind_of Hash, state_hash
592-
assert_equal :bar, state_hash[:foo]
593-
end
594-
end
595-
596-
def test_hash_likeness_set_string
597-
assert_deprecated_warning(/JSON::State/) do
598-
state = JSON.state.new
599-
assert_equal nil, state[:foo]
600-
assert_equal nil, state['foo']
601-
state['foo'] = :bar
602-
assert_equal :bar, state[:foo]
603-
assert_equal :bar, state['foo']
604-
state_hash = state.to_hash
605-
assert_kind_of Hash, state_hash
606-
assert_equal :bar, state_hash[:foo]
607-
end
608-
end
609-
610573
def test_json_state_to_h_roundtrip
611574
state = JSON.state.new
612575
assert_equal state.to_h, JSON.state.new(state.to_h).to_h

0 commit comments

Comments
 (0)