forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelWithJsonTypeIdResolverResource.java
46 lines (36 loc) · 1.29 KB
/
ModelWithJsonTypeIdResolverResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package io.quarkus.it.jackson;
import java.io.IOException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.it.jackson.model.ModelWithJsonTypeIdResolver;
@Path("/typeIdResolver")
public class ModelWithJsonTypeIdResolverResource {
private final ObjectMapper objectMapper;
public ModelWithJsonTypeIdResolverResource(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String post(String body) throws IOException {
ModelWithJsonTypeIdResolver input = objectMapper.readValue(body, ModelWithJsonTypeIdResolver.class);
return input.getType();
}
@GET
@Path("one")
@Produces(MediaType.APPLICATION_JSON)
public String one() throws IOException {
return objectMapper.writeValueAsString(new ModelWithJsonTypeIdResolver.SubclassOne());
}
@GET
@Path("two")
@Produces(MediaType.APPLICATION_JSON)
public String two() throws IOException {
return objectMapper.writeValueAsString(new ModelWithJsonTypeIdResolver.SubclassTwo());
}
}