forcedotcom / forcedotcom/wsc

Can't deserialize to ConnectorConfig

Open
#225 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
276
Forks
223
PR merge metrics
No merged PRs in 30d

Description

I like to store my connection configuration within my larger overall application configuration. I keep my application configuration on disk as a JSON file, and deserialize it with Jackson at runtime:

```java
@Data
public class ApplicationConfiguration
{
@JsonProperty("salesforce")
ConnectorConfig salesforceConfig;
/* ... */
}
```

```json
{
"salesforce": {
"username": "username@example.com",
"password": "password",
"authEndpoint": "https://login.salesforce.com/services/Soap/c/44.0"
},
"...": "..."
}
```

Then, during application startup:

```java
ObjectMapper mapper = new ObjectMapper();
/* ... */
File configFile = new File(configPath);
this.config = mapper.readValue(configFile, ApplicationConfiguration.class);
```

However, ever since #216 added the `ConnectorConfig.sslContext` property, the deserialization throws a `JsonMappingException`:

```
com.fasterxml.jackson.databind.JsonMappingException: Cannot find a deserializer for non-concrete Map type [map type; class java.security.Provider, [simple type, class java.lang.String] -> [simple type, class java.lang.String]]
```

I realize deserializing straight to `ConnectorConfig` probably isn't the best idea in the world. One possible solution would be if `ConnectorConfig` had a constructor which consumed a `Properties` instance, [à la HikariCP](https://github.com/brettwooldridge/HikariCP#initialization). The big thing I want to avoid is internalizing WSC configuration property names within my configuration and copying them all.

## Workaround

I do have a workaround I can use (and offer to anyone else in the same boat): a Jackson mixin which instructs it to ignore the `sslContext` field:

```java
abstract public class ConnectorConfigMixIn
{
@JsonIgnore
abstract public SSLContext getSslContext();
}
```

Then, before the call to `ObjectMapper.readValue()`:

```java
mapper.addMixIn(ConnectorConfig.class, ConnectorConfigMixIn.class);
```

But this feels a bit clumsy.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.