title: Automatically convert JSON to Object on Flask Request
body: <p>In Spring MVC + Jackson (Java), I can have this:</p>
  
  <p><strong>My Object (Java)</strong></p>
  
  <pre><code>public class Project {
  
     private long id;
     private String self;
     private String key;
     private String name;
  
     //Getters and Setters
  }
  </code></pre>
  
  <p><strong>Spring MVC Controller</strong></p>
  
  <pre><code>...
  @RequestMapping(value="/doSomething", method=RequestMethod.POST)
  public String doSomething(@RequestBody Project project) {
      System.out.println(project.getName());
      return "myPage";
  }
  ...
  </code></pre>
  
  <p>Then, I can send a json like: </p>
  
  <pre><code>{"id": "exampleId", "name": "exampleName","self": "url","key": "key"}
  </code></pre>
  
  <p>And automatically it converts to my object. On Python, I have my object class. There's something in Flask that I could call:</p>
  
  <p><strong>Flask Controller</strong></p>
  
  <pre><code>@app.route('/doSomething', methods=['POST'])
  def do_something(project):
      print project.name
      return "myPage"
  </code></pre>
  
  <p><strong>My Object (Python)</strong></p>
  
  <pre><code>class Project():
  
      id=None        
      name=None
      url=None
      key=None
  </code></pre>
  
  <hr>
  
  <p>Essentially, I wanna receive my JSON on Flask and already converts to my Object. I wanna avoid from doing this:</p>
  
  <pre><code>class Project(object):
    def __init__(self, id, url, name, key):
      self.id = id
      self.url = url
      self.name = name
      self.key = key
  ...
  import json
  my_json = json.loads(request.data)
  user = Project(**j)
  </code></pre>
  
  <p>This way, I'll have to override init from all my objects. Or this:</p>
  
  <pre><code>project = json.loads('{"__type__": "Project", "name": "project", "key": "key"}')
  print project['name']
  print project['key']
  </code></pre>
  
  <p>Not good either because it's not my object, it's a dict. </p>
  
  <p>Is this possible? Or I have to choose one of these?</p>