News for hackers. Stuff that matters.
Re:Show HN: Shale – a Ruby object mapper and serializer for ... by WJW on Tuesday May 31, 2022 @09:09AM (#31569043)
In the last example, where does it find the values for the `married`, `age`, `zip` and `hobbies` attributes? They are not present in the JSON string?
Re:Show HN: Shale – a Ruby object mapper and serializer for ... by beerkg on Tuesday May 31, 2022 @09:49AM (#31569444)
Ah, I messed up the example, Person class definition should look like this:

  class Person < Shale::Mapper
    attribute :first_name, Shale::Type::String
    attribute :last_name, Shale::Type::String
    attribute :age, Shale::Type::Integer
    attribute :married, Shale::Type::Boolean, default: false
    attribute :hobbies, Shale::Type::String, collection: true
    attribute :address, Address
  end
And the JSON used for parsing also should contain those atttributes, like:

  {
    "first_name": "John",
    "last_name": "Doe",
    "age": 30,
    "married": false,
    "hobbies": ["Singing", "Dancing"],
    "address": {
      "street": "Oxford Street",
      "city": "London"
    }
  }