### Question:
JsonTranscoder implements Transcoder { @Override public <T> T decode(final Class<T> target, final byte[] input, int flags) { if (target.isAssignableFrom(byte[].class)) { throw InvalidArgumentException.fromMessage("byte[] input is not supported for the JsonTranscoder!. " + "If you want to read already encoded JSON, use the RawJsonTranscoder, otherwise read it " + "with the RawBinaryTranscoder!"); } return serializer.deserialize(target, input); } private  JsonTranscoder(final JsonSerializer serializer); static JsonTranscoder create(JsonSerializer serializer); @Override EncodedValue encode(final Object input); @Override T decode(final Class<T> target, final byte[] input, int flags); @Override T decode(TypeRef<T> target, byte[] input, int flags);  }### Answer:
@Test void rejectsByteArrayDecode() { assertThrows(InvalidArgumentException.class, () -> JSON_TRANSCODER.decode(byte[].class, new byte[] {}, CodecFlags.JSON_COMPAT_FLAGS)); }
@Test void decodesJsonObject() { byte[] input = "{\"foo\":\"bar\"}".getBytes(StandardCharsets.UTF_8); JsonObject decoded = JSON_TRANSCODER.decode(JsonObject.class, input, CodecFlags.JSON_COMPAT_FLAGS); assertEquals(JsonObject.fromJson(input), decoded); }
@Test void decodesJsonArray() { byte[] input = "[\"1\",true,2]".getBytes(StandardCharsets.UTF_8); JsonArray decoded = JSON_TRANSCODER.decode(JsonArray.class, input, CodecFlags.JSON_COMPAT_FLAGS); assertEquals(JsonArray.fromJson(input), decoded); }
@Test void decodesMap() { Map<String, Object> expected = Collections.singletonMap("foo", "bar"); byte[] input = "{\"foo\":\"bar\"}".getBytes(StandardCharsets.UTF_8); Map decoded = JSON_TRANSCODER.decode(Map.class, input, CodecFlags.JSON_COMPAT_FLAGS); assertEquals(expected, decoded); }
@Test void decodesList() { List<Object> expected = Arrays.asList("1", true, 2); byte[] input = "[\"1\",true,2]".getBytes(StandardCharsets.UTF_8); List decoded = JSON_TRANSCODER.decode(List.class, input, CodecFlags.JSON_COMPAT_FLAGS); assertEquals(expected, decoded); }
@Test void decodesSet() { Set<Object> expected = new LinkedHashSet<>(); expected.add("foo"); expected.add("bar"); byte[] input = "[\"foo\",\"bar\"]".getBytes(StandardCharsets.UTF_8); Set decoded = JSON_TRANSCODER.decode(Set.class, input, CodecFlags.JSON_COMPAT_FLAGS); assertEquals(expected, decoded); }