[keycloak-user] Enabling comments in a JSON file?
Eric B
ebenzacar at gmail.com
Wed May 2 14:25:56 EDT 2018
I'd like to add comments to an adapter JSON configuration file to help
document my configuration. However, Keycloak throws an exception when
trying to parse the file:
14:11:53,804 DEBUG [org.keycloak.adapters.jaas.BearerTokenLoginModule]
(default task-15) Unable to find or parse file classpath:/keycloak.json due
to com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/'
(code 47)): maybe a (non-standard) comment? (not recognized as one since
Feature 'ALLOW_COMMENTS' not enabled for parser)
at [Source: java.util.zip.ZipFile$ZipFileInflaterInputStream at 3f9359f3;
line: 1, column: 2]: java.lang.RuntimeException:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/'
(code 47)): maybe a (non-standard) comment? (not recognized as one since
Feature 'ALLOW_COMMENTS' not enabled for parser)
at [Source: java.util.zip.ZipFile$ZipFileInflaterInputStream at 3f9359f3;
line: 1, column: 2]
at
org.keycloak.adapters.KeycloakDeploymentBuilder.loadAdapterConfig(KeycloakDeploymentBuilder.java:162)
at
org.keycloak.adapters.KeycloakDeploymentBuilder.build(KeycloakDeploymentBuilder.java:151)
at
org.keycloak.adapters.jaas.AbstractKeycloakLoginModule.resolveDeployment(AbstractKeycloakLoginModule.java:103)
at
org.keycloak.adapters.jaas.AbstractKeycloakLoginModule.initialize(AbstractKeycloakLoginModule.java:83)
Looking through the code, I see that the Keycloak JSON parser is
created/defined as:
org.keycloak.adapters.KeycloakDeploymentBuilder:
public static AdapterConfig loadAdapterConfig(InputStream is) {
ObjectMapper mapper = new ObjectMapper(new
SystemPropertiesJsonParserFactory());
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
AdapterConfig adapterConfig;
try {
adapterConfig = mapper.readValue(is, AdapterConfig.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
return adapterConfig;
}
Is there anyway I can configure the mapper to allow comments? ie: I'm
looking to set:
SystemPropertiesJsonParserFactory:enable(JsonParser.Feature.
ALLOW_COMMENTS);
But without DependencyInjection, I'm not sure how I can override the
factory definition cleanly, without having to resort to some ugly hacks
(ex: AspectJ, etc).
I'm guessing there might be a way to define a custom
KeycloakDeploymentBuilder, but I can't figure out how to configure that (if
it even exists).
Is there any chance to override/modify these settings?
Thanks,
Eric
More information about the keycloak-user
mailing list