Skip to content

use :from many levels deep #9

@jlecour

Description

@jlecour

Hi,

I'm giving APISmith::Smash a try to map a rich JSON input to Ruby objects.

I have a situation where I have a nested piece of data that I want to map, but not some of its parents.

data = {
  article: {
    titleOfTheArticle: "My Title",
    authorList: {
      author: {
        name: "John Doe"
      }
    },
    details: {
      status: "published"
      updatedAt: '2013-05-10'
    }
  }
}

class Author < APISmith::Smash
  property :name
end

class Article < APISmith::Smash
  property :title, :from => :titleOfTheArticle
  property :author, :transformer => Author
  property :updated_at
end

Here we can see that

  1. there is a nested Author in Article and we do not need to keep the authorList intermediate
  2. the updated_at value, nested inside details would be mapped directly into Article.

Are such things doable with APISmith, or I have to maintain all the hierarchy with classes?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions