mapStars.jsonl
Schema
_key
(required): integer
Range: 40000001 .. 40488503radius
(required): integer
Range: 38185000 .. 2147483647solarSystemID
(required): integer
Range: 30000001 .. 31002604-
statistics
(required): objectage
(required): number
Range: 6538000007692288 .. 2872999969000783900life
(required): number
Range: 27068825224609792 .. 3077000057883459600luminosity
(required): number
Range: 0.01001 .. 34.416161spectralClass
(required): stringtemperature
(required): number
Range: 2010 .. 10764.116211
-
typeID
(required): integer
Range: 6 .. 78350
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var mapStar = MapStar.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class MapStar
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("radius")]
public long Radius { get; set; }
[JsonProperty("solarSystemID")]
public long SolarSystemId { get; set; }
[JsonProperty("statistics")]
public Statistics Statistics { get; set; }
[JsonProperty("typeID")]
public long TypeId { get; set; }
}
public partial class Statistics
{
[JsonProperty("age")]
[JsonConverter(typeof(PurpleMinMaxValueCheckConverter))]
public double Age { get; set; }
[JsonProperty("life")]
[JsonConverter(typeof(FluffyMinMaxValueCheckConverter))]
public double Life { get; set; }
[JsonProperty("luminosity")]
[JsonConverter(typeof(TentacledMinMaxValueCheckConverter))]
public double Luminosity { get; set; }
[JsonProperty("spectralClass")]
[JsonConverter(typeof(MinMaxLengthCheckConverter))]
public string SpectralClass { get; set; }
[JsonProperty("temperature")]
[JsonConverter(typeof(StickyMinMaxValueCheckConverter))]
public double Temperature { get; set; }
}
public partial class MapStar
{
public static MapStar FromJson(string json) => JsonConvert.DeserializeObject<MapStar>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this MapStar self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class PurpleMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= 6538000007692288 && value <= 2872999969000784000)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= 6538000007692288 && value <= 2872999969000784000)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly PurpleMinMaxValueCheckConverter Singleton = new PurpleMinMaxValueCheckConverter();
}
internal class FluffyMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= 27068825224609790 && value <= 3077000057883459600)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= 27068825224609790 && value <= 3077000057883459600)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly FluffyMinMaxValueCheckConverter Singleton = new FluffyMinMaxValueCheckConverter();
}
internal class TentacledMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= 0.01001 && value <= 34.416161)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= 0.01001 && value <= 34.416161)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly TentacledMinMaxValueCheckConverter Singleton = new TentacledMinMaxValueCheckConverter();
}
internal class MinMaxLengthCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(string);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
var value = serializer.Deserialize<string>(reader);
if (value.Length >= 2 && value.Length <= 5)
{
return value;
}
throw new Exception("Cannot unmarshal type string");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
var value = (string)untypedValue;
if (value.Length >= 2 && value.Length <= 5)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type string");
}
public static readonly MinMaxLengthCheckConverter Singleton = new MinMaxLengthCheckConverter();
}
internal class StickyMinMaxValueCheckConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<double>(reader);
if (value >= 2010 && value <= 10764.116211)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (double)untypedValue;
if (value >= 2010 && value <= 10764.116211)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly StickyMinMaxValueCheckConverter Singleton = new StickyMinMaxValueCheckConverter();
}
}
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
// mapStar, err := UnmarshalMapStar(bytes)
// bytes, err = mapStar.Marshal()
package model
import "encoding/json"
func UnmarshalMapStar(data []byte) (MapStar, error) {
var r MapStar
err := json.Unmarshal(data, &r)
return r, err
}
func (r *MapStar) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type MapStar struct {
Key int64 `json:"_key"`
Radius int64 `json:"radius"`
SolarSystemID int64 `json:"solarSystemID"`
Statistics Statistics `json:"statistics"`
TypeID int64 `json:"typeID"`
}
type Statistics struct {
Age float64 `json:"age"`
Life float64 `json:"life"`
Luminosity float64 `json:"luminosity"`
SpectralClass string `json:"spectralClass"`
Temperature float64 `json:"temperature"`
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 40000001,
"maximum": 40488503
},
"radius": {
"type": "integer",
"minimum": 38185000,
"maximum": 2147483647
},
"solarSystemID": {
"type": "integer",
"minimum": 30000001,
"maximum": 31002604
},
"statistics": {
"type": "object",
"properties": {
"age": {
"type": "number",
"minimum": 6.538000007692288E15,
"maximum": 2.8729999690007839E18
},
"life": {
"type": "number",
"minimum": 2.7068825224609792E16,
"maximum": 3.0770000578834596E18
},
"luminosity": {
"type": "number",
"minimum": 0.01001,
"maximum": 34.416161
},
"spectralClass": {
"type": "string",
"minLength": 2,
"maxLength": 5
},
"temperature": {
"type": "number",
"minimum": 2010.0,
"maximum": 10764.116211
}
},
"required": [
"age",
"life",
"luminosity",
"spectralClass",
"temperature"
]
},
"typeID": {
"type": "integer",
"minimum": 6,
"maximum": 78350
}
},
"required": [
"_key",
"radius",
"solarSystemID",
"statistics",
"typeID"
]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val mapStar = json.parse(MapStar.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class MapStar (
@SerialName("_key")
val key: Long,
val radius: Long,
@SerialName("solarSystemID")
val solarSystemId: Long,
val statistics: Statistics,
@SerialName("typeID")
val typeId: Long
)
@Serializable
data class Statistics (
val age: Double,
val life: Double,
val luminosity: Double,
val spectralClass: String,
val temperature: Double
)
<?php
// This is a autogenerated file:MapStar
class MapStar {
private int $key; // json:_key Required
private int $radius; // json:radius Required
private int $solarSystemId; // json:solarSystemID Required
private Statistics $statistics; // json:statistics Required
private int $typeId; // json:typeID Required
/**
* @param int $key
* @param int $radius
* @param int $solarSystemId
* @param Statistics $statistics
* @param int $typeId
*/
public function __construct(int $key, int $radius, int $solarSystemId, Statistics $statistics, int $typeId) {
$this->key = $key;
$this->radius = $radius;
$this->solarSystemId = $solarSystemId;
$this->statistics = $statistics;
$this->typeId = $typeId;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromKey(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toKey(): int {
if (MapStar::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this MapStar::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStar::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (MapStar::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey MapStar::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromRadius(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toRadius(): int {
if (MapStar::validateRadius($this->radius)) {
return $this->radius; /*int*/
}
throw new Exception('never get to this MapStar::radius');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateRadius(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStar::radius");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getRadius(): int {
if (MapStar::validateRadius($this->radius)) {
return $this->radius;
}
throw new Exception('never get to getRadius MapStar::radius');
}
/**
* @return int
*/
public static function sampleRadius(): int {
return 32; /*32:radius*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromSolarSystemId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toSolarSystemId(): int {
if (MapStar::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId; /*int*/
}
throw new Exception('never get to this MapStar::solarSystemId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateSolarSystemId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStar::solarSystemId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getSolarSystemId(): int {
if (MapStar::validateSolarSystemId($this->solarSystemId)) {
return $this->solarSystemId;
}
throw new Exception('never get to getSolarSystemId MapStar::solarSystemId');
}
/**
* @return int
*/
public static function sampleSolarSystemId(): int {
return 33; /*33:solarSystemId*/
}
/**
* @param stdClass $value
* @throws Exception
* @return Statistics
*/
public static function fromStatistics(stdClass $value): Statistics {
return Statistics::from($value); /*class*/
}
/**
* @throws Exception
* @return stdClass
*/
public function toStatistics(): stdClass {
if (MapStar::validateStatistics($this->statistics)) {
return $this->statistics->to(); /*class*/
}
throw new Exception('never get to this MapStar::statistics');
}
/**
* @param Statistics
* @return bool
* @throws Exception
*/
public static function validateStatistics(Statistics $value): bool {
$value->validate();
return true;
}
/**
* @throws Exception
* @return Statistics
*/
public function getStatistics(): Statistics {
if (MapStar::validateStatistics($this->statistics)) {
return $this->statistics;
}
throw new Exception('never get to getStatistics MapStar::statistics');
}
/**
* @return Statistics
*/
public static function sampleStatistics(): Statistics {
return Statistics::sample(); /*34:statistics*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromTypeId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toTypeId(): int {
if (MapStar::validateTypeId($this->typeId)) {
return $this->typeId; /*int*/
}
throw new Exception('never get to this MapStar::typeId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateTypeId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:MapStar::typeId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getTypeId(): int {
if (MapStar::validateTypeId($this->typeId)) {
return $this->typeId;
}
throw new Exception('never get to getTypeId MapStar::typeId');
}
/**
* @return int
*/
public static function sampleTypeId(): int {
return 35; /*35:typeId*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return MapStar::validateKey($this->key)
|| MapStar::validateRadius($this->radius)
|| MapStar::validateSolarSystemId($this->solarSystemId)
|| MapStar::validateStatistics($this->statistics)
|| MapStar::validateTypeId($this->typeId);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'radius'} = $this->toRadius();
$out->{'solarSystemID'} = $this->toSolarSystemId();
$out->{'statistics'} = $this->toStatistics();
$out->{'typeID'} = $this->toTypeId();
return $out;
}
/**
* @param stdClass $obj
* @return MapStar
* @throws Exception
*/
public static function from(stdClass $obj): MapStar {
return new MapStar(
MapStar::fromKey($obj->{'_key'})
,MapStar::fromRadius($obj->{'radius'})
,MapStar::fromSolarSystemId($obj->{'solarSystemID'})
,MapStar::fromStatistics($obj->{'statistics'})
,MapStar::fromTypeId($obj->{'typeID'})
);
}
/**
* @return MapStar
*/
public static function sample(): MapStar {
return new MapStar(
MapStar::sampleKey()
,MapStar::sampleRadius()
,MapStar::sampleSolarSystemId()
,MapStar::sampleStatistics()
,MapStar::sampleTypeId()
);
}
}
// This is a autogenerated file:Statistics
class Statistics {
private float $age; // json:age Required
private float $life; // json:life Required
private float $luminosity; // json:luminosity Required
private string $spectralClass; // json:spectralClass Required
private float $temperature; // json:temperature Required
/**
* @param float $age
* @param float $life
* @param float $luminosity
* @param string $spectralClass
* @param float $temperature
*/
public function __construct(float $age, float $life, float $luminosity, string $spectralClass, float $temperature) {
$this->age = $age;
$this->life = $life;
$this->luminosity = $luminosity;
$this->spectralClass = $spectralClass;
$this->temperature = $temperature;
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromAge(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toAge(): float {
if (Statistics::validateAge($this->age)) {
return $this->age; /*float*/
}
throw new Exception('never get to this Statistics::age');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateAge(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Statistics::age");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getAge(): float {
if (Statistics::validateAge($this->age)) {
return $this->age;
}
throw new Exception('never get to getAge Statistics::age');
}
/**
* @return float
*/
public static function sampleAge(): float {
return 31.031; /*31:age*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromLife(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toLife(): float {
if (Statistics::validateLife($this->life)) {
return $this->life; /*float*/
}
throw new Exception('never get to this Statistics::life');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateLife(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Statistics::life");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getLife(): float {
if (Statistics::validateLife($this->life)) {
return $this->life;
}
throw new Exception('never get to getLife Statistics::life');
}
/**
* @return float
*/
public static function sampleLife(): float {
return 32.032; /*32:life*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromLuminosity(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toLuminosity(): float {
if (Statistics::validateLuminosity($this->luminosity)) {
return $this->luminosity; /*float*/
}
throw new Exception('never get to this Statistics::luminosity');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateLuminosity(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Statistics::luminosity");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getLuminosity(): float {
if (Statistics::validateLuminosity($this->luminosity)) {
return $this->luminosity;
}
throw new Exception('never get to getLuminosity Statistics::luminosity');
}
/**
* @return float
*/
public static function sampleLuminosity(): float {
return 33.033; /*33:luminosity*/
}
/**
* @param string $value
* @throws Exception
* @return string
*/
public static function fromSpectralClass(string $value): string {
return $value; /*string*/
}
/**
* @throws Exception
* @return string
*/
public function toSpectralClass(): string {
if (Statistics::validateSpectralClass($this->spectralClass)) {
return $this->spectralClass; /*string*/
}
throw new Exception('never get to this Statistics::spectralClass');
}
/**
* @param string
* @return bool
* @throws Exception
*/
public static function validateSpectralClass(string $value): bool {
if (!is_string($value)) {
throw new Exception("Attribute Error:Statistics::spectralClass");
}
return true;
}
/**
* @throws Exception
* @return string
*/
public function getSpectralClass(): string {
if (Statistics::validateSpectralClass($this->spectralClass)) {
return $this->spectralClass;
}
throw new Exception('never get to getSpectralClass Statistics::spectralClass');
}
/**
* @return string
*/
public static function sampleSpectralClass(): string {
return 'Statistics::spectralClass::34'; /*34:spectralClass*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromTemperature(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toTemperature(): float {
if (Statistics::validateTemperature($this->temperature)) {
return $this->temperature; /*float*/
}
throw new Exception('never get to this Statistics::temperature');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateTemperature(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Statistics::temperature");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getTemperature(): float {
if (Statistics::validateTemperature($this->temperature)) {
return $this->temperature;
}
throw new Exception('never get to getTemperature Statistics::temperature');
}
/**
* @return float
*/
public static function sampleTemperature(): float {
return 35.035; /*35:temperature*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Statistics::validateAge($this->age)
|| Statistics::validateLife($this->life)
|| Statistics::validateLuminosity($this->luminosity)
|| Statistics::validateSpectralClass($this->spectralClass)
|| Statistics::validateTemperature($this->temperature);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'age'} = $this->toAge();
$out->{'life'} = $this->toLife();
$out->{'luminosity'} = $this->toLuminosity();
$out->{'spectralClass'} = $this->toSpectralClass();
$out->{'temperature'} = $this->toTemperature();
return $out;
}
/**
* @param stdClass $obj
* @return Statistics
* @throws Exception
*/
public static function from(stdClass $obj): Statistics {
return new Statistics(
Statistics::fromAge($obj->{'age'})
,Statistics::fromLife($obj->{'life'})
,Statistics::fromLuminosity($obj->{'luminosity'})
,Statistics::fromSpectralClass($obj->{'spectralClass'})
,Statistics::fromTemperature($obj->{'temperature'})
);
}
/**
* @return Statistics
*/
public static function sample(): Statistics {
return new Statistics(
Statistics::sampleAge()
,Statistics::sampleLife()
,Statistics::sampleLuminosity()
,Statistics::sampleSpectralClass()
,Statistics::sampleTemperature()
);
}
}
from typing import Any, TypeVar, Type, cast
T = TypeVar("T")
def from_float(x: Any) -> float:
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def from_str(x: Any) -> str:
assert isinstance(x, str)
return x
def to_float(x: Any) -> float:
assert isinstance(x, (int, float))
return x
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
class Statistics:
age: float
life: float
luminosity: float
spectral_class: str
temperature: float
def __init__(self, age: float, life: float, luminosity: float, spectral_class: str, temperature: float) -> None:
self.age = age
self.life = life
self.luminosity = luminosity
self.spectral_class = spectral_class
self.temperature = temperature
@staticmethod
def from_dict(obj: Any) -> 'Statistics':
assert isinstance(obj, dict)
age = from_float(obj.get("age"))
life = from_float(obj.get("life"))
luminosity = from_float(obj.get("luminosity"))
spectral_class = from_str(obj.get("spectralClass"))
temperature = from_float(obj.get("temperature"))
return Statistics(age, life, luminosity, spectral_class, temperature)
def to_dict(self) -> dict:
result: dict = {}
result["age"] = to_float(self.age)
result["life"] = to_float(self.life)
result["luminosity"] = to_float(self.luminosity)
result["spectralClass"] = from_str(self.spectral_class)
result["temperature"] = to_float(self.temperature)
return result
class MapStar:
key: int
radius: int
solar_system_id: int
statistics: Statistics
type_id: int
def __init__(self, key: int, radius: int, solar_system_id: int, statistics: Statistics, type_id: int) -> None:
self.key = key
self.radius = radius
self.solar_system_id = solar_system_id
self.statistics = statistics
self.type_id = type_id
@staticmethod
def from_dict(obj: Any) -> 'MapStar':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
radius = from_int(obj.get("radius"))
solar_system_id = from_int(obj.get("solarSystemID"))
statistics = Statistics.from_dict(obj.get("statistics"))
type_id = from_int(obj.get("typeID"))
return MapStar(key, radius, solar_system_id, statistics, type_id)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["radius"] = from_int(self.radius)
result["solarSystemID"] = from_int(self.solar_system_id)
result["statistics"] = to_class(Statistics, self.statistics)
result["typeID"] = from_int(self.type_id)
return result
def map_star_from_dict(s: Any) -> MapStar:
return MapStar.from_dict(s)
def map_star_to_dict(x: MapStar) -> Any:
return to_class(MapStar, x)
// To parse this data:
//
// import { Convert, MapStar } from "./file";
//
// const mapStar = Convert.toMapStar(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface MapStar {
_key: number;
radius: number;
solarSystemID: number;
statistics: Statistics;
typeID: number;
[property: string]: any;
}
export interface Statistics {
age: number;
life: number;
luminosity: number;
spectralClass: string;
temperature: number;
[property: string]: any;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toMapStar(json: string): MapStar {
return cast(JSON.parse(json), r("MapStar"));
}
public static mapStarToJson(value: MapStar): string {
return JSON.stringify(uncast(value, r("MapStar")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"MapStar": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "radius", js: "radius", typ: 0 },
{ json: "solarSystemID", js: "solarSystemID", typ: 0 },
{ json: "statistics", js: "statistics", typ: r("Statistics") },
{ json: "typeID", js: "typeID", typ: 0 },
], "any"),
"Statistics": o([
{ json: "age", js: "age", typ: 3.14 },
{ json: "life", js: "life", typ: 3.14 },
{ json: "luminosity", js: "luminosity", typ: 3.14 },
{ json: "spectralClass", js: "spectralClass", typ: "" },
{ json: "temperature", js: "temperature", typ: 3.14 },
], "any"),
};