1 | /*- | |
2 | * #%L | |
3 | * io.earcam.utilitarian.web.jaxrs | |
4 | * %% | |
5 | * Copyright (C) 2017 earcam | |
6 | * %% | |
7 | * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
8 | * | |
9 | * You <b>must</b> choose to accept, in full - any individual or combination of | |
10 | * the following licenses: | |
11 | * <ul> | |
12 | * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
13 | * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
14 | * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
15 | * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
16 | * </ul> | |
17 | * #L% | |
18 | */ | |
19 | package io.earcam.utilitarian.web.jaxrs; | |
20 | ||
21 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | |
22 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON_PATCH_JSON_TYPE; | |
23 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | |
24 | ||
25 | import java.io.InputStream; | |
26 | import java.lang.annotation.Annotation; | |
27 | import java.lang.reflect.Type; | |
28 | import java.util.Objects; | |
29 | ||
30 | import javax.json.bind.Jsonb; | |
31 | import javax.json.bind.JsonbBuilder; | |
32 | import javax.ws.rs.Consumes; | |
33 | import javax.ws.rs.core.MediaType; | |
34 | import javax.ws.rs.core.MultivaluedMap; | |
35 | import javax.ws.rs.ext.MessageBodyReader; | |
36 | import javax.ws.rs.ext.Provider; | |
37 | ||
38 | import io.earcam.unexceptional.Exceptional; | |
39 | ||
40 | @Consumes(APPLICATION_JSON) | |
41 | @Provider | |
42 | public class JsonMessageBodyReader implements MessageBodyReader<Object> { | |
43 | ||
44 | static final Jsonb JSONB = JsonbBuilder.create(); | |
45 | ||
46 | ||
47 | @Override | |
48 | public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) | |
49 | { | |
50 |
1
1. isReadable : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return isJson(mediaType); |
51 | } | |
52 | ||
53 | ||
54 | static boolean isJson(MediaType mediaType) | |
55 | { | |
56 |
3
1. isJson : negated conditional → KILLED 2. isJson : negated conditional → KILLED 3. isJson : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return equalIgnoringParameters(APPLICATION_JSON_TYPE, mediaType) || equalIgnoringParameters(APPLICATION_JSON_PATCH_JSON_TYPE, mediaType); |
57 | } | |
58 | ||
59 | ||
60 | private static boolean equalIgnoringParameters(MediaType a, MediaType b) | |
61 | { | |
62 |
2
1. equalIgnoringParameters : negated conditional → KILLED 2. equalIgnoringParameters : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return Objects.equals(a.getType(), b.getType()) |
63 |
1
1. equalIgnoringParameters : negated conditional → KILLED |
&& Objects.equals(a.getSubtype(), b.getSubtype()); |
64 | } | |
65 | ||
66 | ||
67 | @Override | |
68 | public Object readFrom(Class<Object> type, Type genericType, Annotation[] annos, MediaType mediaType, MultivaluedMap<String, String> h, InputStream in) | |
69 | { | |
70 |
1
1. readFrom : mutated return of Object value for io/earcam/utilitarian/web/jaxrs/JsonMessageBodyReader::readFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return Exceptional.apply(JSONB::fromJson, in, genericType); |
71 | } | |
72 | } | |
Mutations | ||
50 |
1.1 |
|
56 |
1.1 2.2 3.3 |
|
62 |
1.1 2.2 |
|
63 |
1.1 |
|
70 |
1.1 |