Skip to content

Commit

Permalink
Merge pull request #380 from auth0/fix-roles
Browse files Browse the repository at this point in the history
Fix de/serialization of Invitation roles
  • Loading branch information
lbalmaceda authored Oct 5, 2021
2 parents 297980f + f4bc1fa commit 3b935d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/auth0/json/mgmt/organizations/Invitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.fasterxml.jackson.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* Represents the Invitation object for an organization.
*
* @see com.auth0.client.mgmt.OrganizationsEntity
*/
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down Expand Up @@ -44,14 +46,14 @@ public class Invitation {
@JsonProperty("organization_id")
private String organizationId;
@JsonProperty("roles")
private Roles roles;
private List<String> roles;

/**
* Create a new instance.
*
* @param inviter the {@linkplain Inviter} of this invitation.
* @param invitee the {@linkplain Invitee} of this invitation.
* @param clientId The id of the connection the invitee will authenticate with.\
* @param inviter the {@linkplain Inviter} of this invitation.
* @param invitee the {@linkplain Invitee} of this invitation.
* @param clientId Auth0 client ID. Used to resolve the application's login initiation endpoint.
*/
@JsonCreator
public Invitation(@JsonProperty("inviter") Inviter inviter, @JsonProperty("invitee") Invitee invitee, @JsonProperty("client_id") String clientId) {
Expand Down Expand Up @@ -193,17 +195,19 @@ public String getTicketId() {
/**
* @return the roles associated with the user invited.
*/
@JsonIgnore
public Roles getRoles() {
return roles;
return new Roles(roles);
}

/**
* Sets the roles to be associated with the user invited.
*
* @param roles the {@linkplain Roles} to associated with the user invited.
*/
@JsonIgnore
public void setRoles(Roles roles) {
this.roles = roles;
this.roles = roles.getRoles();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ public void shouldDeserialize() throws Exception {
" \"ticket_id\": \"ticket-id\",\n" +
" \"created_at\": \"2021-03-31T19:08:40.295Z\",\n" +
" \"expires_at\": \"2021-04-07T19:08:40.295Z\",\n" +
" \"organization_id\": \"org_abc\"\n" +
" \"organization_id\": \"org_abc\",\n" +
" \"roles\": [\n" +
" \"rol_0987\"\n" +
" ]\n" +
"}\n";

Invitation invitation = fromJSON(json, Invitation.class);

assertThat(invitation, is(notNullValue()));
assertThat(invitation.getRoles().getRoles(), is(contains("rol_0987")));
assertThat(invitation.getId(), is("inv_1"));
assertThat(invitation.getClientId(), is("client-id"));
assertThat(invitation.getInviter(), is(notNullValue()));
Expand Down

0 comments on commit 3b935d6

Please sign in to comment.