<?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};
enum EnumType : string
{
case Value1 = 'Value1';
case Value2 = 'Value2';
case Value3 = 'Value3';
}
enum EnumWithValues : string
{
case None = 'None';
case Value1 = 'Member 1';
case Value2 = 'Value2';
}
// @Flags()
enum EnumFlags : int
{
case Value0 = 0;
case Value1 = 1;
case Value2 = 2;
case Value3 = 4;
case Value123 = 7;
}
enum EnumStyle : string
{
case lower = 'lower';
case UPPER = 'UPPER';
case PascalCase = 'PascalCase';
case camelCase = 'camelCase';
case camelUPPER = 'camelUPPER';
case PascalUPPER = 'PascalUPPER';
}
class HelloWithEnumList implements JsonSerializable
{
public function __construct(
/** @var array<EnumType>|null */
public ?array $enumProp=null,
/** @var array<EnumWithValues>|null */
public ?array $enumWithValues=null,
/** @var array<EnumType>|null */
public ?array $nullableEnumProp=null,
/** @var array<EnumFlags>|null */
public ?array $enumFlags=null,
/** @var array<EnumStyle>|null */
public ?array $enumStyle=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['enumProp'])) $this->enumProp = JsonConverters::fromArray('EnumType', $o['enumProp']);
if (isset($o['enumWithValues'])) $this->enumWithValues = JsonConverters::fromArray('EnumWithValues', $o['enumWithValues']);
if (isset($o['nullableEnumProp'])) $this->nullableEnumProp = JsonConverters::fromArray('Nullable<EnumType>', $o['nullableEnumProp']);
if (isset($o['enumFlags'])) $this->enumFlags = JsonConverters::fromArray('EnumFlags', $o['enumFlags']);
if (isset($o['enumStyle'])) $this->enumStyle = JsonConverters::fromArray('EnumStyle', $o['enumStyle']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->enumProp)) $o['enumProp'] = JsonConverters::toArray('EnumType', $this->enumProp);
if (isset($this->enumWithValues)) $o['enumWithValues'] = JsonConverters::toArray('EnumWithValues', $this->enumWithValues);
if (isset($this->nullableEnumProp)) $o['nullableEnumProp'] = JsonConverters::toArray('Nullable<EnumType>', $this->nullableEnumProp);
if (isset($this->enumFlags)) $o['enumFlags'] = JsonConverters::toArray('EnumFlags', $this->enumFlags);
if (isset($this->enumStyle)) $o['enumStyle'] = JsonConverters::toArray('EnumStyle', $this->enumStyle);
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 /jsonl/oneway/HelloWithEnumList HTTP/1.1
Host: test.servicestack.net
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length
{"enumProp":["Value1"],"enumWithValues":["None"],"nullableEnumProp":["Value1"],"enumFlags":[0],"enumStyle":["lower"]}