### Question:
HeaderDeserializer extends StdDeserializer<BasicHeader> { @Override public BasicHeader deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { Map<String, JsonNode> tree = p.getCodec().readValue(p, new TypeReference<Map<String, JsonNode>>() { }); if (tree == null) { throw new JWTDecodeException("Parsing the Header's JSON resulted on a Null map"); } String algorithm = getString(tree, PublicClaims.ALGORITHM); String type = getString(tree, PublicClaims.TYPE); String contentType = getString(tree, PublicClaims.CONTENT_TYPE); String keyId = getString(tree, PublicClaims.KEY_ID); return new BasicHeader(algorithm, type, contentType, keyId, tree, objectReader); } HeaderDeserializer(ObjectReader objectReader); private  HeaderDeserializer(Class<?> vc, ObjectReader objectReader); @Override BasicHeader deserialize(JsonParser p, DeserializationContext ctxt);  }### Answer:
@Test public void shouldThrowOnNullTree() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("Parsing the Header's JSON resulted on a Null map"); JsonDeserializer deserializer = new HeaderDeserializer(objectReader); JsonParser parser = mock(JsonParser.class); ObjectCodec codec = mock(ObjectCodec.class); DeserializationContext context = mock(DeserializationContext.class); when(codec.readValue(eq(parser), any(TypeReference.class))).thenReturn(null); when(parser.getCodec()).thenReturn(codec); deserializer.deserialize(parser, context); }
@Test public void shouldNotRemoveKnownPublicClaimsFromTree() throws Exception { String headerJSON = "{\n" + " \"alg\": \"HS256\",\n" + " \"typ\": \"jws\",\n" + " \"cty\": \"content\",\n" + " \"kid\": \"key\",\n" + " \"roles\": \"admin\"\n" + "}"; StringReader reader = new StringReader(headerJSON); JsonParser jsonParser = new JsonFactory().createParser(reader); ObjectMapper mapper = new ObjectMapper(); jsonParser.setCodec(mapper); Header header = deserializer.deserialize(jsonParser, mapper.getDeserializationContext()); assertThat(header, is(notNullValue())); assertThat(header.getAlgorithm(), is("HS256")); assertThat(header.getType(), is("jws")); assertThat(header.getContentType(), is("content")); assertThat(header.getKeyId(), is("key")); assertThat(header.getHeaderClaim("roles").asString(), is("admin")); assertThat(header.getHeaderClaim("alg").asString(), is("HS256")); assertThat(header.getHeaderClaim("typ").asString(), is("jws")); assertThat(header.getHeaderClaim("cty").asString(), is("content")); assertThat(header.getHeaderClaim("kid").asString(), is("key")); }