import datetime
import decimal
from marshmallow.fields import *
from servicestack import *
from typing import *
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, LetterCase, Undefined, config
from enum import Enum, IntEnum
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class SubType:
id: int = 0
name: Optional[str] = None
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class AllTypes(IGet):
id: int = 0
nullable_id: Optional[int] = None
byte: int = 0
short: int = 0
int_: int = field(metadata=config(field_name='int'), default=0)
long: int = 0
u_short: int = 0
u_int: int = 0
u_long: int = 0
float_: float = field(metadata=config(field_name='float'), default=0.0)
double: float = 0.0
decimal: Decimal = decimal.Decimal(0)
string: Optional[str] = None
date_time: datetime.datetime = datetime.datetime(1, 1, 1)
time_span: datetime.timedelta = datetime.timedelta()
date_time_offset: datetime.datetime = datetime.datetime(1, 1, 1)
guid: Optional[str] = None
char: Optional[str] = None
key_value_pair: Optional[KeyValuePair[str, str]] = None
nullable_date_time: Optional[datetime.datetime] = None
nullable_time_span: Optional[datetime.timedelta] = None
string_list: List[str] = field(default_factory=list)
string_array: List[str] = field(default_factory=list)
string_map: Dict[str, str] = field(default_factory=dict)
int_string_map: Dict[int, str] = field(default_factory=dict)
sub_type: Optional[SubType] = None
point: Optional[str] = None
original_name: Optional[str] = None
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class Poco:
name: Optional[str] = None
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class AllCollectionTypes:
int_array: List[int] = field(default_factory=list)
int_list: List[int] = field(default_factory=list)
string_array: List[str] = field(default_factory=list)
string_list: List[str] = field(default_factory=list)
poco_array: List[Poco] = field(default_factory=list)
poco_list: List[Poco] = field(default_factory=list)
nullable_byte_array: List[Optional[int]] = field(default_factory=list)
nullable_byte_list: List[int] = field(default_factory=list)
nullable_date_time_array: List[Optional[datetime.datetime]] = field(default_factory=list)
nullable_date_time_list: List[datetime.datetime] = field(default_factory=list)
poco_lookup: Dict[str, List[Poco]] = field(default_factory=dict)
poco_lookup_map: Dict[str, List[Dict[str, Poco]]] = field(default_factory=dict)
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class HelloAllTypesResponse:
result: Optional[str] = None
all_types: Optional[AllTypes] = None
all_collection_types: Optional[AllCollectionTypes] = None
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class HelloAllTypes:
name: Optional[str] = None
all_types: Optional[AllTypes] = None
all_collection_types: Optional[AllCollectionTypes] = None
To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /jsv/reply/HelloAllTypes HTTP/1.1
Host: blazor-gallery.servicestack.net
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length
{
name: String,
allTypes:
{
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: 0001-01-01,
timeSpan: PT0S,
dateTimeOffset: 0001-01-01T00:00:00.0000000+00:00,
guid: 00000000000000000000000000000000,
char: ,
keyValuePair:
{
key: String,
value: String
},
nullableDateTime: 0001-01-01,
nullableTimeSpan: PT0S,
stringList:
[
String
],
stringArray:
[
String
],
stringMap:
{
String: String
},
intStringMap:
{
0: String
},
subType:
{
id: 0,
name: String
},
point: "0,0",
aliasedName: String
},
allCollectionTypes:
{
intArray:
[
0
],
intList:
[
0
],
stringArray:
[
String
],
stringList:
[
String
],
pocoArray:
[
{
name: String
}
],
pocoList:
[
{
name: String
}
],
nullableByteArray:
[
0
],
nullableByteList:
[
0
],
nullableDateTimeArray:
[
0001-01-01
],
nullableDateTimeList:
[
0001-01-01
],
pocoLookup:
{
String:
[
{
name: String
}
]
},
pocoLookupMap:
{
String:
[
{
String:
{
name: String
}
}
]
}
}
}
HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { result: String, allTypes: { 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: 0001-01-01, timeSpan: PT0S, dateTimeOffset: 0001-01-01T00:00:00.0000000+00:00, guid: 00000000000000000000000000000000, char: , keyValuePair: { key: String, value: String }, nullableDateTime: 0001-01-01, nullableTimeSpan: PT0S, stringList: [ String ], stringArray: [ String ], stringMap: { String: String }, intStringMap: { 0: String }, subType: { id: 0, name: String }, point: "0,0", aliasedName: String }, allCollectionTypes: { intArray: [ 0 ], intList: [ 0 ], stringArray: [ String ], stringList: [ String ], pocoArray: [ { name: String } ], pocoList: [ { name: String } ], nullableByteArray: [ 0 ], nullableByteList: [ 0 ], nullableDateTimeArray: [ 0001-01-01 ], nullableDateTimeList: [ 0001-01-01 ], pocoLookup: { String: [ { name: String } ] }, pocoLookupMap: { String: [ { String: { name: String } } ] } } }