-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add a custom component class to resolve serialization issues wit…
…h JSONB
- Loading branch information
1 parent
6b7f4e6
commit c9b3ad8
Showing
2 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rilabs/keycloak/configurator/commands/configure/entity/CustomComponentRepresentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.cycrilabs.keycloak.configurator.commands.configure.entity; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import org.keycloak.common.util.MultivaluedHashMap; | ||
import org.keycloak.representations.idm.ComponentRepresentation; | ||
|
||
/** | ||
* Custom representation of a Keycloak component that avoids MultivaluedHashMap for the config property. | ||
* This class can't be serialized/deserialized out-of-the-box by JSONB. | ||
*/ | ||
@Getter | ||
@Setter | ||
public class CustomComponentRepresentation { | ||
|
||
private String id; | ||
private String name; | ||
private String providerId; | ||
private String providerType; | ||
private String parentId; | ||
private String subType; | ||
private Map<String, List<String>> config; | ||
|
||
public ComponentRepresentation toAPI() { | ||
final ComponentRepresentation componentRepresentation = new ComponentRepresentation(); | ||
componentRepresentation.setId(id); | ||
componentRepresentation.setName(name); | ||
componentRepresentation.setProviderId(providerId); | ||
componentRepresentation.setProviderType(providerType); | ||
componentRepresentation.setParentId(parentId); | ||
componentRepresentation.setSubType(subType); | ||
componentRepresentation.setConfig(new MultivaluedHashMap<>(config)); | ||
return componentRepresentation; | ||
} | ||
|
||
public static CustomComponentRepresentation fromAPI(final ComponentRepresentation componentRepresentation) { | ||
final CustomComponentRepresentation customComponentRepresentation = new CustomComponentRepresentation(); | ||
customComponentRepresentation.setId(componentRepresentation.getId()); | ||
customComponentRepresentation.setName(componentRepresentation.getName()); | ||
customComponentRepresentation.setProviderId(componentRepresentation.getProviderId()); | ||
customComponentRepresentation.setProviderType(componentRepresentation.getProviderType()); | ||
customComponentRepresentation.setParentId(componentRepresentation.getParentId()); | ||
customComponentRepresentation.setSubType(componentRepresentation.getSubType()); | ||
customComponentRepresentation.setConfig(componentRepresentation.getConfig()); | ||
return customComponentRepresentation; | ||
} | ||
|
||
} |