Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix de/serialization of Invitation roles #380

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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