jacksonapache-camelcamel-jackson

Prevent camel-jackson from removing quotation marks


I am working on a camel route for a REST service. My task is to add a POST in which I need to take a token out of the json that is sent. I am doing the following:

.unmarshal().json(JsonLibrary.Jackson, Token.class)

I added the "camel-jackson" dependency to my pom file and it works fine.

Problem: Now all the json coming is has the double quotation marks stripped off. So the following json:

{"name": "John Doe", "job": "farmer"}

Ends up as:

{name:John Doe,job:farmer}

For some of my code I need the double quotes. I have tried to do a bit of configuring my rest route with no luck. Any one have an idea of a fix?


Solution

  • You mention in the comment that you have

    restConfiguration()
        .component("jetty") 
        .scheme("https") 
        .bindingMode(RestBindingMode.auto) 
        .dataFormatProperty("prettyPrint", "true") 
        .port(8443);
    

    You don't mention what your route is. However, if you're using bindingMode it will expect a type() on the get()/post() which will be used to unmarshal json into. It sounds like you only want to do this for the new POST you are adding, so why not have the binding on the post() rather than globally on the restConfiguration()?

    e.g.

    restConfiguration()
        .component("jetty") 
        .scheme("https") 
        .dataFormatProperty("prettyPrint", "true") 
        .port(8443);
    
    rest("/words")
        .post("/new/post/url")
            .bindingMode(RestBindingMode.auto) 
            .type(YourPojo.class)
            ... 
        .get("existing/stuff")
            ...