Search in sources :

Example 6 with UserPojo

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

the class PayloadSerializerTest method shouldSerializeCustomObject.

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

Example 7 with UserPojo

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

the class JsonNodeClaimTest method shouldGetListValueOfCustomClass.

@Test
public void shouldGetListValueOfCustomClass() {
    JsonNode value = mapper.valueToTree(Arrays.asList(new UserPojo("George", 1), new UserPojo("Mark", 2)));
    Claim claim = claimFromNode(value);
    assertThat(claim.asList(UserPojo.class), is(notNullValue()));
    assertThat(claim.asList(UserPojo.class), is(hasItems(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 8 with UserPojo

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

the class JsonNodeClaimTest method shouldDelegateToJsonNodeToString.

@Test
public void shouldDelegateToJsonNodeToString() {
    JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
    Claim claim = claimFromNode(value);
    assertThat(claim.toString(), is(value.toString()));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 9 with UserPojo

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

the class JsonNodeClaimTest method shouldReturnNullForInvalidArrayValue.

@Test
public void shouldReturnNullForInvalidArrayValue() {
    JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
    Claim claim = claimFromNode(value);
    assertNull(claim.asArray(String.class));
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 10 with UserPojo

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

the class JsonNodeClaimTest method shouldThrowIfCustomClassMismatch.

@Test
public void shouldThrowIfCustomClassMismatch() {
    JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
    Claim claim = claimFromNode(value);
    exception.expect(JWTDecodeException.class);
    claim.as(String.class);
}
Also used : UserPojo(com.auth0.jwt.UserPojo) JsonNode(com.fasterxml.jackson.databind.JsonNode) Claim(com.auth0.jwt.interfaces.Claim) 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