diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index c368c21c0a..ce4c805c9b 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -73,7 +73,7 @@ class Hash
# configure your own builder with the :builder option. The method also accepts
# options like :dasherize and friends, they are forwarded to the builder.
def to_xml(options = {})
- require "active_support/builder" unless defined?(Builder)
+ require "active_support/builder" unless defined?(Builder) && defined?(Builder::XmlMarkup)
options = options.dup
options[:indent] ||= 2