camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sirlatrom <...@git.apache.org>
Subject [GitHub] camel pull request #1033: Add option to use Java 1.8 `Optional<?>` for POJO ...
Date Tue, 14 Jun 2016 15:44:44 GMT
GitHub user sirlatrom opened a pull request:

    https://github.com/apache/camel/pull/1033

    Add option to use Java 1.8 `Optional<?>` for POJO fields

    Also upgrades to Jackson 2.x to allow injecting a custom `ObjectMapper` into `SalesforceEndpointConfig`,
which in turn allows registering the `Jdk8Module` when using Java 1.8, which handles (de)serializing
of `Optional<?>` in a reasonable manner. Jackson 1.x does not have the `Jdk8Module`.
    
    Note that this requires that the project using the plugin is itself using Java 1.8+.
    
    To use `Jdk8Module`, add this dependency:
    ```xml
    		<dependency>
    			<groupId>com.fasterxml.jackson.datatype</groupId>
    			<artifactId>jackson-datatype-jdk8</artifactId>
    		</dependency>
    ```
    
    Then configure a custom `ObjectMapper` like the following snippet:
    ```java
    import org.apache.camel.component.salesforce.SalesforceEndpointConfig;
    ...
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.databind.SerializationFeature;
    import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
    ...
    	@Bean
    	public SalesforceEndpointConfig salesforceEndpointConfig() {
    		SalesforceEndpointConfig salesforceEndpointConfig = new SalesforceEndpointConfig();
    		...
    		ObjectMapper objectMapper = new ObjectMapper();
    		objectMapper.registerModule(new Jdk8Module());
    		objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    		salesforceEndpointConfig.setObjectMapper(objectMapper);
    		return salesforceEndpointConfig;
    	}
    ```
    
    Signed-off-by: Sune Keller <absukl@almbrand.dk>

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sirlatrom/camel feature/option-generate-pojos-with-java-8-optional-fields

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/camel/pull/1033.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1033
    
----
commit 64a715c7edcf49e9b3b9c10d5e15fcb570d3e08e
Author: Sune Keller <absukl@almbrand.dk>
Date:   2016-06-14T14:32:01Z

    Add option to use Java 1.8 Optional<?> for POJO fields
    
    Also upgrades to Jackson 2.x to allow injecting a custom
    `ObjectMapper`, which in turn allows registering the `Jdk8Module`
    when using Java 1.8, which handles (de)serializing of Optional<?>
    in a reasonable manner.
    
    Signed-off-by: Sune Keller <absukl@almbrand.dk>

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message