MediaType { public static boolean isJson(String mediaType) { MediaType type = from(mediaType); return (type.getType().equals("application") && type.getSubtypeWithoutSuffix().equals("json")) || type.getSuffix().filter(s -> s.equals("json")).isPresent(); } private  MediaType(String value, String type, String subtype, Map<String, String> parameters); static MediaType from(String value); static boolean isJson(String mediaType); String getType(); String getSubtype(); String getSubtypeWithoutSuffix(); Map<String, String> getParameters(); Optional<String> getSuffix(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void detectsJsonMediaTypes() { assertThat(MediaType.isJson("application/json"), is(true)); assertThat(MediaType.isJson("application/foo+json"), is(true)); assertThat(MediaType.isJson("foo/json"), is(false)); assertThat(MediaType.isJson("application/jsonn"), is(false)); assertThat(MediaType.isJson("application/foo+jsonn"), is(false)); }