All Verbs | /testdata/AllTypes |
---|
<?php namespace dtos;
use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};
class SubType implements JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var string */
public string $name=''
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['name'])) $this->name = $o['name'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->name)) $o['name'] = $this->name;
return empty($o) ? new class(){} : $o;
}
}
class AllTypes implements JsonSerializable
{
public function __construct(
/** @var int */
public int $id=0,
/** @var int|null */
public ?int $nullableId=null,
/** @var int */
public int $byte=0,
/** @var int */
public int $short=0,
/** @var int */
public int $int=0,
/** @var int */
public int $long=0,
/** @var int */
public int $uShort=0,
/** @var int */
public int $uInt=0,
/** @var int */
public int $uLong=0,
/** @var float */
public float $float=0.0,
/** @var float */
public float $double=0.0,
/** @var float */
public float $decimal=0.0,
/** @var string */
public string $string='',
/** @var DateTime */
public DateTime $dateTime=new DateTime(),
/** @var DateInterval|null */
public ?DateInterval $timeSpan=null,
/** @var DateTime */
public DateTime $dateTimeOffset=new DateTime(),
/** @var string */
public string $guid='',
/** @var string */
public string $char='',
/** @var KeyValuePair2<string, string>|null */
public ?KeyValuePair2 $keyValuePair=null,
/** @var DateTime|null */
public ?DateTime $nullableDateTime=null,
/** @var DateInterval|null */
public ?DateInterval $nullableTimeSpan=null,
/** @var array<string>|null */
public ?array $stringList=null,
/** @var string[] */
public array $stringArray=[],
/** @var array<string,string>|null */
public ?array $stringMap=null,
/** @var array<string,string>|null */
public ?array $intStringMap=null,
/** @var SubType|null */
public ?SubType $subType=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['nullableId'])) $this->nullableId = $o['nullableId'];
if (isset($o['byte'])) $this->byte = $o['byte'];
if (isset($o['short'])) $this->short = $o['short'];
if (isset($o['int'])) $this->int = $o['int'];
if (isset($o['long'])) $this->long = $o['long'];
if (isset($o['uShort'])) $this->uShort = $o['uShort'];
if (isset($o['uInt'])) $this->uInt = $o['uInt'];
if (isset($o['uLong'])) $this->uLong = $o['uLong'];
if (isset($o['float'])) $this->float = $o['float'];
if (isset($o['double'])) $this->double = $o['double'];
if (isset($o['decimal'])) $this->decimal = $o['decimal'];
if (isset($o['string'])) $this->string = $o['string'];
if (isset($o['dateTime'])) $this->dateTime = JsonConverters::from('DateTime', $o['dateTime']);
if (isset($o['timeSpan'])) $this->timeSpan = JsonConverters::from('DateInterval', $o['timeSpan']);
if (isset($o['dateTimeOffset'])) $this->dateTimeOffset = JsonConverters::from('DateTime', $o['dateTimeOffset']);
if (isset($o['guid'])) $this->guid = $o['guid'];
if (isset($o['char'])) $this->char = $o['char'];
if (isset($o['keyValuePair'])) $this->keyValuePair = JsonConverters::from(JsonConverters::context('KeyValuePair2',genericArgs:['string','string']), $o['keyValuePair']);
if (isset($o['nullableDateTime'])) $this->nullableDateTime = JsonConverters::from('DateTime', $o['nullableDateTime']);
if (isset($o['nullableTimeSpan'])) $this->nullableTimeSpan = JsonConverters::from('TimeSpan', $o['nullableTimeSpan']);
if (isset($o['stringList'])) $this->stringList = JsonConverters::fromArray('string', $o['stringList']);
if (isset($o['stringArray'])) $this->stringArray = JsonConverters::fromArray('string', $o['stringArray']);
if (isset($o['stringMap'])) $this->stringMap = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['stringMap']);
if (isset($o['intStringMap'])) $this->intStringMap = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['int','string']), $o['intStringMap']);
if (isset($o['subType'])) $this->subType = JsonConverters::from('SubType', $o['subType']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->nullableId)) $o['nullableId'] = $this->nullableId;
if (isset($this->byte)) $o['byte'] = $this->byte;
if (isset($this->short)) $o['short'] = $this->short;
if (isset($this->int)) $o['int'] = $this->int;
if (isset($this->long)) $o['long'] = $this->long;
if (isset($this->uShort)) $o['uShort'] = $this->uShort;
if (isset($this->uInt)) $o['uInt'] = $this->uInt;
if (isset($this->uLong)) $o['uLong'] = $this->uLong;
if (isset($this->float)) $o['float'] = $this->float;
if (isset($this->double)) $o['double'] = $this->double;
if (isset($this->decimal)) $o['decimal'] = $this->decimal;
if (isset($this->string)) $o['string'] = $this->string;
if (isset($this->dateTime)) $o['dateTime'] = JsonConverters::to('DateTime', $this->dateTime);
if (isset($this->timeSpan)) $o['timeSpan'] = JsonConverters::to('DateInterval', $this->timeSpan);
if (isset($this->dateTimeOffset)) $o['dateTimeOffset'] = JsonConverters::to('DateTime', $this->dateTimeOffset);
if (isset($this->guid)) $o['guid'] = $this->guid;
if (isset($this->char)) $o['char'] = $this->char;
if (isset($this->keyValuePair)) $o['keyValuePair'] = JsonConverters::to(JsonConverters::context('KeyValuePair2',genericArgs:['string','string']), $this->keyValuePair);
if (isset($this->nullableDateTime)) $o['nullableDateTime'] = JsonConverters::to('DateTime', $this->nullableDateTime);
if (isset($this->nullableTimeSpan)) $o['nullableTimeSpan'] = JsonConverters::to('TimeSpan', $this->nullableTimeSpan);
if (isset($this->stringList)) $o['stringList'] = JsonConverters::toArray('string', $this->stringList);
if (isset($this->stringArray)) $o['stringArray'] = JsonConverters::toArray('string', $this->stringArray);
if (isset($this->stringMap)) $o['stringMap'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->stringMap);
if (isset($this->intStringMap)) $o['intStringMap'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['int','string']), $this->intStringMap);
if (isset($this->subType)) $o['subType'] = JsonConverters::to('SubType', $this->subType);
return empty($o) ? new class(){} : $o;
}
}
class TestDataAllTypes implements JsonSerializable
{
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .other suffix or ?format=other
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /testdata/AllTypes HTTP/1.1
Host: test.servicestack.net
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length
{}
HTTP/1.1 200 OK Content-Type: text/jsonl Content-Length: length {"id":0,"nullableId":0,"byte":0,"short":0,"int":0,"long":0,"uShort":0,"uInt":0,"uLong":0,"float":0,"double":0,"decimal":0,"string":"String","dateTime":"\/Date(-62135596800000-0000)\/","timeSpan":"PT0S","dateTimeOffset":"\/Date(-62135596800000)\/","guid":"00000000000000000000000000000000","char":"\u0000","keyValuePair":{"key":"String","value":"String"},"nullableDateTime":"\/Date(-62135596800000-0000)\/","nullableTimeSpan":"PT0S","stringList":["String"],"stringArray":["String"],"stringMap":{"String":"String"},"intStringMap":{"0":"String"},"subType":{"id":0,"name":"String"}}