nesaulov/surrealist

Conflict when root and and object property share the same name

Closed this issue · 1 comments

There seems to be a problem with serializing an object with a root that is the same as one of it's properties.

Foo = Struct.new(:foo, :bar)
Foo.include Surrealist
Foo.json_schema { { bar: String } }

foo = Foo.new('foo', 'bar')

foo.surrealize
# => "{\"bar\":\"bar\"}"

foo.surrealize(include_root: true)
# Surrealist::UndefinedMethodError: undefined method `bar' for "foo":String. You have probably defined a key in the schema that doesn't have a corresponding method.

foo.surrealize(root: 'foo')
# Surrealist::UndefinedMethodError: undefined method `bar' for "foo":String. You have probably defined a key in the schema that doesn't have a corresponding method.

foo.surrealize(root: 'fooz')
# => "{\"fooz\":{\"bar\":\"bar\"}}"

Hm, that's a bug. @huyderman thank you for the issue, and would you like to introduce a PR?