Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JSON Validation with TWTValidation by Jill Cohen

JSON Validation with TWTValidation by Jill Cohen

Lightning Talk from March 2015 CocoaHeads Raleigh/Durham

More Decks by Triangle Cocoa - Lightning Talks

Other Decks in Programming

Transcript

  1. JSON VALIDATION PROBLEM: Writing validation code is tedious and error-prone

    Requires frequent & consistent type checking Often fails silently Repetitive Low readability Perform mapping before completing validation
  2. JSON VALIDATION USING TWTVALIDATION GET JSON VALUE VALIDATE VALUE AGAINST

    EXPECTATIONS IF PASSES,
 PERFORM MAPPING Describe expected format as a single entity, not with successive if statements
  3. ▸ Usage: JSON VALIDATION VALIDATE, THEN MAP INTO MODEL OBJECTS

    CONFIDENTLY Correct types!
 Won’t crash! Required values are guaranteed to be present!
  4. JSON VALIDATION EXAMPLE SCHEMA: WEATHER is described
 by… Explicit when

    allowing null Enforce types Require existence of properties Define common structure once
  5. JSON VALIDATION UNDER THE HOOD PARSES SCHEMA INTO ABSTRACT SYNTAX

    TREE VALIDATE VALUE PROCESSES TREE USING VISITOR PATTERN TO GENERATE VALIDATOR Composes existing classes of TWTValidators 
 + some classes purpose-built for this Requires input to be a valid schema Nested validators perform their specific validation tasks