<commit_before>
//Define some interfaces
//that we want our JSON structure to look like

interface Person extends JsonObject {
   AddressList addresses;

}


interface AddressList extends List, JsonObject {
  Address address;
}

interface Address extends JsonObject {
   String line1;
   String postcode;
}

// this test will fail.  But it would be great if it didn't!
// does anyone have any ideas?
testStrongTyping() {
  print("testStrongTyping");
  var jsonString = _getStrongTypingJsonString();

  // Create a new JSON object which looks like our Person
  // A Person Interface extends the JsonObject, so no
  // warning is reported

  Person person = new JsonObject.fromJsonString(jsonString); // this will fail.



  //verify property access
  expect(person.addresses[0].address.line1, equals("1 the street"));

  var noSuchMethodException = null;
  try {
    //this should throw an exception
    //as it doesn't exist on Person
    //and it is a valid warning
    person.wibble;
  }
  catch (NoSuchMethodException ex) {
    noSuchMethodException = ex;
  }

  expect(noSuchMethodException != null);

}


_getStrongTypingJsonString() {
//Create the JSON which looks like our interface structure
  var jsonString = """
      {
        "addresses" : [
          { "address": {
              "line1": "1 the street",
              "postcode": "ab12 3de"
            }
          },
          { "address": {
              "line1": "1 the street",
              "postcode": "ab12 3de"
            }
          }
        ]
      }
      """;
  return jsonString;
}<commit_msg>Make strong typing work for JsonObject. Base approach as in Objectory<commit_after>
//Define some interfaces
//that we want our JSON structure to look like

interface Person default _PersonImpl{
   AddressList addresses;
   Person.fromString(String jsonString);
}

class _PersonImpl extends JsonObject implements Person {
  _PersonImpl();
  factory _PersonImpl.fromString(String jsonString) {
    return new JsonObject.fromJsonString(jsonString, new _PersonImpl());  
  } 
}


interface AddressList extends List, JsonObject {
  Address address;
}

interface Address extends JsonObject {
   String line1;
   String postcode;
}

// this test will fail.  But it would be great if it didn't!
// does anyone have any ideas?
testStrongTyping() {
  print("testStrongTyping");
  String jsonString = _getStrongTypingJsonString();

  // Create a new JSON object which looks like our Person
  // A Person Interface extends the JsonObject, so no
  // warning is reported

  Person person = new Person.fromString(jsonString); // this will not fail
  


  //verify property access
  expect(person.addresses[0].address.line1, equals("1 the street"));

  var noSuchMethodException = null;
  try {
    //this should throw an exception
    //as it doesn't exist on Person
    //and it is a valid warning
    person.wibble;
  }
  catch (NoSuchMethodException ex) {
    noSuchMethodException = ex;
  }

  expect(noSuchMethodException != null);

}


String _getStrongTypingJsonString() {
//Create the JSON which looks like our interface structure
  var jsonString = """
      {
        "addresses" : [
          { "address": {
              "line1": "1 the street",
              "postcode": "ab12 3de"
            }
          },
          { "address": {
              "line1": "1 the street",
              "postcode": "ab12 3de"
            }
          }
        ]
      }
      """;
  return jsonString;
}
{'fraction_non_alphanumeric': 0.09393063583815028, 'fraction_numerical': 0.008092485549132947, 'mean_word_length': 2.5680412371134023, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2823474', 'n_tokens_mistral': 1004, 'n_tokens_neox': 959, 'n_words': 331}