### Question:
PayloadDeserializer extends StdDeserializer<Payload> { @Override public Payload 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 Payload's JSON resulted on a Null map"); } String issuer = getString(tree, PublicClaims.ISSUER); String subject = getString(tree, PublicClaims.SUBJECT); List<String> audience = getStringOrArray(tree, PublicClaims.AUDIENCE); Date expiresAt = getDateFromSeconds(tree, PublicClaims.EXPIRES_AT); Date notBefore = getDateFromSeconds(tree, PublicClaims.NOT_BEFORE); Date issuedAt = getDateFromSeconds(tree, PublicClaims.ISSUED_AT); String jwtId = getString(tree, PublicClaims.JWT_ID); return new PayloadImpl(issuer, subject, audience, expiresAt, notBefore, issuedAt, jwtId, tree, objectReader); } PayloadDeserializer(ObjectReader reader); private  PayloadDeserializer(Class<?> vc, ObjectReader reader); @Override Payload deserialize(JsonParser p, DeserializationContext ctxt);  }### Answer:
@Test public void shouldThrowOnNullTree() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("Parsing the Payload's JSON resulted on a Null map"); 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 payloadJSON = "{\n" + " \"iss\": \"auth0\",\n" + " \"sub\": \"emails\",\n" + " \"aud\": \"users\",\n" + " \"iat\": 10101010,\n" + " \"exp\": 11111111,\n" + " \"nbf\": 10101011,\n" + " \"jti\": \"idid\",\n" + " \"roles\":\"admin\" \n" + "}"; StringReader reader = new StringReader(payloadJSON); JsonParser jsonParser = new JsonFactory().createParser(reader); ObjectMapper mapper = new ObjectMapper(); jsonParser.setCodec(mapper); Payload payload = deserializer.deserialize(jsonParser, mapper.getDeserializationContext()); assertThat(payload, is(notNullValue())); assertThat(payload.getIssuer(), is("auth0")); assertThat(payload.getSubject(), is("emails")); assertThat(payload.getAudience(), is(IsCollectionContaining.hasItem("users"))); assertThat(payload.getIssuedAt().getTime(), is(10101010L * 1000)); assertThat(payload.getExpiresAt().getTime(), is(11111111L * 1000)); assertThat(payload.getNotBefore().getTime(), is(10101011L * 1000)); assertThat(payload.getId(), is("idid")); assertThat(payload.getClaim("roles").asString(), is("admin")); assertThat(payload.getClaim("iss").asString(), is("auth0")); assertThat(payload.getClaim("sub").asString(), is("emails")); assertThat(payload.getClaim("aud").asString(), is("users")); assertThat(payload.getClaim("iat").asDouble(), is(10101010D)); assertThat(payload.getClaim("exp").asDouble(), is(11111111D)); assertThat(payload.getClaim("nbf").asDouble(), is(10101011D)); assertThat(payload.getClaim("jti").asString(), is("idid")); }