# Unable to create a dry-struct from a hash with string keys

**URL:** https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520
**Category:** dry-types
**Created:** [March 28, 2018, 5:06pm UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520 "2018-03-28T17:06:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chrismanderson](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/chrismanderson/32/174_2.png) [@chrismanderson](https://discourse.dry-rb.org/u/chrismanderson)
#### Post date: [March 28, 2018, 5:06pm UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520/1 "2018-03-28T17:06:29Z")

</div>

If I have a hash

```auto
{ "name" => "Bob", "age" => 12 }

```

with a class

```auto
class DryUser < Dry::Struct
  attribute :name, Types::String
  attribute :age, Types::Int
end

```

The attributes are not being set correctly.

```auto
irb(main):172:0> DryUser.new("name" => "Bob", "age" => 12)
=> #<DryUser name=nil age=nil>
irb(main):173:0>

```

This works with Virtus

```auto
class VirtusUser
  include Virtus.model

  attribute :name, String
  attribute :age, Int
end

```

```auto
irb(main):197:0> VirtusUser.new("name" => "Bob", "age" => 12)
=> #<VirtusUser:0x00007f829ea663f0 @name="Bob", @age=12>

```

How do I make this work with dry-struct? I searched the documentation and found `constructor_type :symbolized`, but that didn’t work with `dry-struct`.

I know these gems aren’t the same but this feels like a common use case and would appreciate any help you all can offer. Thanks!

---

<div class="post-metadata">

### Author: ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)
#### Post date: [March 28, 2018, 5:48pm UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520/2 "2018-03-28T17:48:26Z")

</div>

It will be available in the next version, see for more information [https://github.com/dry-rb/dry-struct/pull/64](https://github.com/dry-rb/dry-struct/pull/64)

---

<div class="post-metadata">

### Author: ![chrismanderson](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/chrismanderson/32/174_2.png) [@chrismanderson](https://discourse.dry-rb.org/u/chrismanderson)
#### Post date: [March 29, 2018, 1:17pm UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520/3 "2018-03-29T13:17:27Z")

</div>

That’s great news. To confirm, in the next version, I’d use `transform_keys` to convert the hash keys into symbols, correct?

---

<div class="post-metadata">

### Author: ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)
#### Post date: [April 1, 2018, 11:22am UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520/4 "2018-04-01T11:22:01Z")

</div>

Yes.

* * *

Here’s an unrelated text because our discourse doesn’t allow messages less than 20 characters long /cc @solnic

---

<div class="post-metadata">

### Author: ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)
#### Post date: [April 2, 2018, 11:56pm UTC](https://discourse.dry-rb.org/t/unable-to-create-a-dry-struct-from-a-hash-with-string-keys/520/5 "2018-04-02T23:56:05Z")

</div>

Updated it to minimum 2. Now you can say “Yes” or “No”, @flash-gordon 😆 (/cc @solnic)
