You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/serializers/custom.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Implement the platform's `Serializer` interface (or appropriate base type):
8
8
9
9
=== "C#"
10
10
11
-
On .NET, TypedRest uses `MediaTypeFormatter` from the `System.Net.Http.Formatting` family. Derive from `MediaTypeFormatter` (or one of its specializations) and override the read/write methods.
11
+
TypedRest uses `MediaTypeFormatter` from the `System.Net.Http.Formatting` family. Derive from `MediaTypeFormatter` (or one of its specializations) and override the read/write methods.
12
12
13
13
```csharp
14
14
using System.Net.Http.Formatting;
@@ -106,10 +106,10 @@ Implement the platform's `Serializer` interface (or appropriate base type):
106
106
107
107
=== "TypeScript"
108
108
109
-
Implement the `Serializer` interface from the `typedrest` package:
109
+
Implement the `Serializer` interface:
110
110
111
111
```typescript
112
-
import { Serializer } from "typedrest";
112
+
import { Serializer } from "typedrest/serializers";
Copy file name to clipboardExpand all lines: docs/serializers/json.md
+106-5Lines changed: 106 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,7 @@ JSON is the default serialization format in TypedRest.
14
14
- Automatic type name handling
15
15
16
16
```csharp
17
-
var endpoint = new EntryEndpoint(new Uri("http://example.com/"));
18
-
// Uses NewtonsoftJsonSerializer by default
17
+
var endpoint = new EntryEndpoint(new Uri("http://example.com/")); // Uses NewtonsoftJsonSerializer by default
19
18
```
20
19
21
20
To customize the serializer settings:
@@ -63,13 +62,115 @@ JSON is the default serialization format in TypedRest.
63
62
});
64
63
```
65
64
65
+
=== "Java"
66
+
67
+
**kotlinx.serialization (Default)**
68
+
69
+
The default serializer uses [kotlinx.serialization](https://kotlinlang.org/docs/serialization.html). Entity classes are typically defined in Kotlin with the `@Serializable` annotation.
70
+
71
+
```java
72
+
EntryEndpoint endpoint = new EntryEndpoint(URI.create("http://example.com/")); // Uses KotlinxJsonSerializer by default
73
+
```
74
+
75
+
**Jackson**
76
+
77
+
For Java POJOs or more control over serialization, add the [typedrest-serializers-jackson](https://central.sonatype.com/artifact/net.typedrest/typedrest-serializers-jackson) dependency and pass a `JacksonJsonSerializer`:
78
+
79
+
```java
80
+
EntryEndpoint endpoint = new EntryEndpoint(URI.create("http://example.com/"), null, new JacksonJsonSerializer());
EntryEndpoint endpoint = new EntryEndpoint(URI.create("http://example.com/"), null, new JacksonJsonSerializer(mapper));
91
+
```
92
+
93
+
**Moshi**
94
+
95
+
Add the [typedrest-serializers-moshi](https://central.sonatype.com/artifact/net.typedrest/typedrest-serializers-moshi) dependency and pass a `MoshiJsonSerializer`:
96
+
97
+
```java
98
+
EntryEndpoint endpoint = new EntryEndpoint(URI.create("http://example.com/"), null, new MoshiJsonSerializer());
99
+
```
100
+
101
+
=== "Kotlin"
102
+
103
+
**kotlinx.serialization (Default)**
104
+
105
+
The default serializer uses [kotlinx.serialization](https://kotlinlang.org/docs/serialization.html). Annotate entity classes with `@Serializable`:
106
+
107
+
```kotlin
108
+
import kotlinx.serialization.Serializable
109
+
110
+
@Serializable
111
+
data class Contact(val name: String)
112
+
```
113
+
114
+
```kotlin
115
+
val endpoint = EntryEndpoint(URI.create("http://example.com/")) // Uses KotlinxJsonSerializer by default
116
+
```
117
+
118
+
**Jackson**
119
+
120
+
Add the [typedrest-serializers-jackson](https://central.sonatype.com/artifact/net.typedrest/typedrest-serializers-jackson) dependency and pass a `JacksonJsonSerializer`:
Add the [typedrest-serializers-moshi](https://central.sonatype.com/artifact/net.typedrest/typedrest-serializers-moshi) dependency and pass a `MoshiJsonSerializer`:
145
+
146
+
```kotlin
147
+
val endpoint = EntryEndpoint(
148
+
URI.create("http://example.com/"),
149
+
serializer = MoshiJsonSerializer()
150
+
)
151
+
```
152
+
153
+
To customize the `Moshi` instance:
154
+
155
+
```kotlin
156
+
val moshi = Moshi.Builder()
157
+
.add(KotlinJsonAdapterFactory())
158
+
.add(Date::class.java, Rfc3339DateJsonAdapter())
159
+
.build()
160
+
val endpoint = EntryEndpoint(
161
+
URI.create("http://example.com/"),
162
+
serializer = MoshiJsonSerializer(moshi)
163
+
)
164
+
```
165
+
66
166
=== "TypeScript"
67
167
68
-
TypeScript uses the native `JSON.stringify()` and `JSON.parse()` methods:
168
+
**Native JSON (Default)**
169
+
170
+
The default serializer uses the native `JSON.stringify()` and `JSON.parse()` methods.
69
171
70
172
```typescript
71
-
const endpoint = new EntryEndpoint(new URL("http://example.com/"));
72
-
// Uses JsonSerializer by default
173
+
const endpoint = new EntryEndpoint(new URL("http://example.com/")); // Uses JsonSerializer by default
0 commit comments