You need to add the option to the model in camel-core as well.

On Wed, Dec 7, 2016 at 6:22 PM,  <acosent...@apache.org> wrote:
> Repository: camel
> Updated Branches:
>   refs/heads/master 31cce6bc9 -> 7567488f8
>
>
> CAMEL-10567: Camel-Jackson: Add an option to allow the UnmarshallType header 
> use
>
>
> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7567488f
> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7567488f
> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7567488f
>
> Branch: refs/heads/master
> Commit: 7567488f844f01d72840f7ab6ca18114a11f20d8
> Parents: 31cce6b
> Author: Andrea Cosentino <anco...@gmail.com>
> Authored: Wed Dec 7 18:18:45 2016 +0100
> Committer: Andrea Cosentino <anco...@gmail.com>
> Committed: Wed Dec 7 18:22:13 2016 +0100
>
> ----------------------------------------------------------------------
>  .../component/jackson/JacksonDataFormat.java    | 19 ++++++-
>  ...arshalUnmarshalTypeHeaderNotAllowedTest.java | 54 ++++++++++++++++++++
>  .../JacksonMarshalUnmarshalTypeHeaderTest.java  |  1 +
>  3 files changed, 73 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/7567488f/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
> ----------------------------------------------------------------------
> diff --git 
> a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
>  
> b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
> index 154c387..4772619 100644
> --- 
> a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
> +++ 
> b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
> @@ -68,6 +68,7 @@ public class JacksonDataFormat extends ServiceSupport 
> implements DataFormat, Dat
>      private String enableFeatures;
>      private String disableFeatures;
>      private boolean enableJacksonTypeConverter;
> +    private boolean allowJacksonUnmarshallType;
>
>      /**
>       * Use the default Jackson {@link ObjectMapper} and {@link Object}
> @@ -158,7 +159,10 @@ public class JacksonDataFormat extends ServiceSupport 
> implements DataFormat, Dat
>
>          // is there a header with the unmarshal type?
>          Class<?> clazz = unmarshalType;
> -        String type = 
> exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class);
> +        String type = null;
> +        if (allowJacksonUnmarshallType) {
> +            type = 
> exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class);
> +        }
>          if (type == null && isAllowJmsType()) {
>              type = exchange.getIn().getHeader("JMSType", String.class);
>          }
> @@ -326,6 +330,19 @@ public class JacksonDataFormat extends ServiceSupport 
> implements DataFormat, Dat
>      public void setEnableJacksonTypeConverter(boolean 
> enableJacksonTypeConverter) {
>          this.enableJacksonTypeConverter = enableJacksonTypeConverter;
>      }
> +
> +    public boolean isAllowJacksonUnmarshallType() {
> +        return allowJacksonUnmarshallType;
> +    }
> +
> +    /**
> +     * If enabled then Jackson is allowed to attempt to use the 
> CamelJacksonUnmarshalType header during the unmarshalling.
> +     * <p/>
> +     * This should only be enabled when desired to be used.
> +     */
> +    public void setAllowJacksonUnmarshallType(boolean 
> allowJacksonUnmarshallType) {
> +        this.allowJacksonUnmarshallType = allowJacksonUnmarshallType;
> +    }
>
>      public String getEnableFeatures() {
>          return enableFeatures;
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/7567488f/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
> ----------------------------------------------------------------------
> diff --git 
> a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
>  
> b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
> new file mode 100644
> index 0000000..ffabeeb
> --- /dev/null
> +++ 
> b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
> @@ -0,0 +1,54 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.camel.component.jackson;
> +
> +import java.util.LinkedHashMap;
> +
> +import org.apache.camel.builder.RouteBuilder;
> +import org.apache.camel.component.mock.MockEndpoint;
> +import org.apache.camel.test.junit4.CamelTestSupport;
> +import org.junit.Test;
> +
> +public class JacksonMarshalUnmarshalTypeHeaderNotAllowedTest extends 
> CamelTestSupport {
> +
> +    @Test
> +    public void testUnmarshalPojo() throws Exception {
> +        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
> +        mock.expectedMessageCount(1);
> +        mock.message(0).body().isInstanceOf(LinkedHashMap.class);
> +
> +        String json = "{\"name\":\"Camel\"}";
> +        template.sendBodyAndHeader("direct:backPojo", json, 
> JacksonConstants.UNMARSHAL_TYPE, TestPojo.class.getName());
> +
> +        assertMockEndpointsSatisfied();
> +    }
> +
> +    @Override
> +    protected RouteBuilder createRouteBuilder() throws Exception {
> +        return new RouteBuilder() {
> +
> +            @Override
> +            public void configure() throws Exception {
> +                JacksonDataFormat format = new JacksonDataFormat();
> +
> +                
> from("direct:backPojo").unmarshal(format).to("mock:reversePojo");
> +
> +            }
> +        };
> +    }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/7567488f/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
> ----------------------------------------------------------------------
> diff --git 
> a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
>  
> b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
> index 9cb5b59..623b32e 100644
> --- 
> a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
> +++ 
> b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
> @@ -46,6 +46,7 @@ public class JacksonMarshalUnmarshalTypeHeaderTest extends 
> CamelTestSupport {
>              @Override
>              public void configure() throws Exception {
>                  JacksonDataFormat format = new JacksonDataFormat();
> +                format.setAllowJacksonUnmarshallType(true);
>
>                  
> from("direct:backPojo").unmarshal(format).to("mock:reversePojo");
>
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to