Search in sources :

Example 1 with UserPojo

use of com.auth0.jwt.UserPojo in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldGetAsMapValue.

@SuppressWarnings({ "unchecked", "RedundantCast" })
@Test
public void shouldGetAsMapValue() {
    JsonNode value = mapper.valueToTree(Collections.singletonMap("key", new UserPojo("john", 123)));
    Claim claim = claimFromNode(value);
    assertThat(claim, is(notNullValue()));
    Map map = claim.as(Map.class);
    assertThat(((Map<String, Object>) map.get("key")), hasEntry("name", (Object) "john"));
    assertThat(((Map<String, Object>) map.get("key")), hasEntry("id", (Object) 123));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 2 with UserPojo

use of com.auth0.jwt.UserPojo in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldConvertToString.

@Test
public void shouldConvertToString() {
    JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
    JsonNode nullValue = mapper.valueToTree(null);
    JsonNode missingValue = MissingNode.getInstance();
    Claim claim = claimFromNode(value);
    Claim nullClaim = claimFromNode(nullValue);
    Claim missingClaim = claimFromNode(missingValue);
    assertThat(claim.toString(), is("{\"name\":\"john\",\"id\":123}"));
    assertThat(nullClaim.isNull(), is(true));
    assertThat(nullClaim.toString(), is("Null claim"));
    assertThat(missingClaim.isMissing(), is(true));
    assertThat(missingClaim.toString(), is("Missing claim"));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 3 with UserPojo

use of com.auth0.jwt.UserPojo in project java-jwt by auth0.

the class JsonNodeClaimTest method shouldGetArrayValueOfCustomClass.

@Test
public void shouldGetArrayValueOfCustomClass() {
    JsonNode value = mapper.valueToTree(new UserPojo[] { new UserPojo("George", 1), new UserPojo("Mark", 2) });
    Claim claim = claimFromNode(value);
    assertThat(claim.asArray(UserPojo.class), is(notNullValue()));
    assertThat(claim.asArray(UserPojo.class), is(arrayContaining(new UserPojo("George", 1), new UserPojo("Mark", 2))));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 4 with UserPojo

use of com.auth0.jwt.UserPojo in project java-jwt by auth0.

the class PayloadSerializerTest method shouldSerializeCustomListOfObject.

@Test
public void shouldSerializeCustomListOfObject() throws Exception {
    UserPojo user1 = new UserPojo("Michael", 1);
    UserPojo user2 = new UserPojo("Lucas", 2);
    PayloadClaimsHolder holder = holderFor("users", Arrays.asList(user1, user2));
    serializer.serialize(holder, jsonGenerator, serializerProvider);
    jsonGenerator.flush();
    assertThat(writer.toString(), is(equalTo("{\"users\":[{\"name\":\"Michael\",\"id\":1},{\"name\":\"Lucas\",\"id\":2}]}")));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) Test(org.junit.Test)

Example 5 with UserPojo

use of com.auth0.jwt.UserPojo in project java-jwt by auth0.

the class PayloadSerializerTest method shouldSerializeCustomArrayOfObject.

@Test
public void shouldSerializeCustomArrayOfObject() throws Exception {
    UserPojo user1 = new UserPojo("Michael", 1);
    UserPojo user2 = new UserPojo("Lucas", 2);
    PayloadClaimsHolder holder = holderFor("users", new UserPojo[] { user1, user2 });
    serializer.serialize(holder, jsonGenerator, serializerProvider);
    jsonGenerator.flush();
    assertThat(writer.toString(), is(equalTo("{\"users\":[{\"name\":\"Michael\",\"id\":1},{\"name\":\"Lucas\",\"id\":2}]}")));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) Test(org.junit.Test)

Aggregations

UserPojo (com.auth0.jwt.UserPojo)11 Test (org.junit.Test)11 Claim (com.auth0.jwt.interfaces.Claim)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)8