fromJson static method
Posts?
fromJson(
- dynamic value
)
Returns a new Posts instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Posts? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
assert(json.containsKey(r'user_id'), 'Required key "Posts[user_id]" is missing from JSON.');
assert(json[r'user_id'] != null, 'Required key "Posts[user_id]" has a null value in JSON.');
assert(json.containsKey(r'company_id'), 'Required key "Posts[company_id]" is missing from JSON.');
assert(json[r'company_id'] != null, 'Required key "Posts[company_id]" has a null value in JSON.');
assert(json.containsKey(r'title'), 'Required key "Posts[title]" is missing from JSON.');
assert(json[r'title'] != null, 'Required key "Posts[title]" has a null value in JSON.');
assert(json.containsKey(r'content_html'), 'Required key "Posts[content_html]" is missing from JSON.');
assert(json[r'content_html'] != null, 'Required key "Posts[content_html]" has a null value in JSON.');
assert(json.containsKey(r'data_cost_credits'), 'Required key "Posts[data_cost_credits]" is missing from JSON.');
assert(json[r'data_cost_credits'] != null, 'Required key "Posts[data_cost_credits]" has a null value in JSON.');
assert(json.containsKey(r'service_cost_credits'), 'Required key "Posts[service_cost_credits]" is missing from JSON.');
assert(json[r'service_cost_credits'] != null, 'Required key "Posts[service_cost_credits]" has a null value in JSON.');
assert(json.containsKey(r'total_cost_credits'), 'Required key "Posts[total_cost_credits]" is missing from JSON.');
assert(json[r'total_cost_credits'] != null, 'Required key "Posts[total_cost_credits]" has a null value in JSON.');
assert(json.containsKey(r'successful_insights_count'), 'Required key "Posts[successful_insights_count]" is missing from JSON.');
assert(json[r'successful_insights_count'] != null, 'Required key "Posts[successful_insights_count]" has a null value in JSON.');
assert(json.containsKey(r'failed_insights_count'), 'Required key "Posts[failed_insights_count]" is missing from JSON.');
assert(json[r'failed_insights_count'] != null, 'Required key "Posts[failed_insights_count]" has a null value in JSON.');
assert(json.containsKey(r'is_published'), 'Required key "Posts[is_published]" is missing from JSON.');
assert(json[r'is_published'] != null, 'Required key "Posts[is_published]" has a null value in JSON.');
assert(json.containsKey(r'view_count'), 'Required key "Posts[view_count]" is missing from JSON.');
assert(json[r'view_count'] != null, 'Required key "Posts[view_count]" has a null value in JSON.');
return true;
}());
return Posts(
dateCreated: mapDateTime(json, r'date_created', r''),
lastUpdated: mapDateTime(json, r'last_updated', r''),
postId: mapValueOfType<String>(json, r'post_id'),
userId: mapValueOfType<String>(json, r'user_id')!,
companyId: mapValueOfType<String>(json, r'company_id')!,
title: mapValueOfType<String>(json, r'title')!,
category: mapValueOfType<String>(json, r'category'),
teaser: mapValueOfType<String>(json, r'teaser'),
contentHtml: mapValueOfType<String>(json, r'content_html')!,
insightsUsed: mapValueOfType<Object>(json, r'insights_used'),
generationCreativity: mapValueOfType<int>(json, r'generation_creativity'),
generationTargetWordCount: mapValueOfType<int>(json, r'generation_target_word_count'),
generationTone: mapValueOfType<String>(json, r'generation_tone'),
generationIncludeCitations: mapValueOfType<bool>(json, r'generation_include_citations'),
generationSubheadingCount: mapValueOfType<int>(json, r'generation_subheading_count'),
generationTemperature: mapValueOfType<double>(json, r'generation_temperature'),
dataCostCredits: mapValueOfType<int>(json, r'data_cost_credits')!,
serviceCostCredits: mapValueOfType<int>(json, r'service_cost_credits')!,
totalCostCredits: mapValueOfType<int>(json, r'total_cost_credits')!,
successfulInsightsCount: mapValueOfType<int>(json, r'successful_insights_count')!,
failedInsightsCount: mapValueOfType<int>(json, r'failed_insights_count')!,
generationTimeMs: mapValueOfType<int>(json, r'generation_time_ms'),
isPublished: mapValueOfType<bool>(json, r'is_published')!,
publishedAt: mapDateTime(json, r'published_at', r''),
viewCount: mapValueOfType<int>(json, r'view_count')!,
lastEditedAt: mapDateTime(json, r'last_edited_at', r''),
);
}
return null;
}