You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by sirlatrom <gi...@git.apache.org> on 2016/06/14 15:44:44 UTC

[GitHub] camel pull request #1033: Add option to use Java 1.8 `Optional` for POJO ...

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 <ab...@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 <ab...@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 <ab...@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.
---

[GitHub] camel pull request #1033: Add option to use Java 1.8 `Optional` for POJO ...

Posted by sirlatrom <gi...@git.apache.org>.
Github user sirlatrom closed the pull request at:

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


---
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.
---